Skip to main content

I would like to write a Script that can vary it's logic based on what session it is running under.

How  can I get the current session name or title?

Thanks,

Mark Hecht


#Rumba

I would like to write a Script that can vary it's logic based on what session it is running under.

How  can I get the current session name or title?

Thanks,

Mark Hecht


#Rumba

Hi Mark,

Unfortunately the Rumba script interface does not expose this information. However, assuming your session is the active window (i.e. has focus), then you can use the Windows API to scrape the title bar text from the foreground window and parse the Session name from that.

Here is some sample code:

Declare Function GetForegroundWindow Lib "user32" () As Long

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Sub Main

Dim Sys As Object, Sess As Object

       Dim hWnd As Long, x As Long, ForegroundSessionName As String, j As Integer, TitleLen as Integer

       hWnd = GetForegroundWindow

       If hWnd > 0 Then

  TitleLen = GetWindowTextLength(hWnd) 1

          ForegroundSessionName = String(GetWindowTextLength(hWnd) 1, Chr$(0))

          x = GetWindowText(hWnd, ForegroundSessionName, TitleLen)

  Msgbox Chr$(9) & "Window Handle = " & hWnd & Chr$(13) & Chr$(10) & Chr$(9) & "Window Title = " & ForegroundSessionName, 64

      End If

End Sub

If your Rumba session does not have focus, but you only have one Rumba frame open and the session you need to identify is active within the Rumba frame, then you can query the open windows using FindNextWindow (again from user32.dll) until you find the Rumba frame and then parse the session name out.

Regards,

Tom


I would like to write a Script that can vary it's logic based on what session it is running under.

How  can I get the current session name or title?

Thanks,

Mark Hecht


#Rumba

Almost surely I'm wrong but the in some of my script I use:

' Get Current Alias of the connection

EMGetCurrentAlias CurrentAlias

' Connect to the current terminal

EMConnect CurrentAlias

to be sure to use the right connection as I use multiple script running at the same time, maybe you can parse the "CurrentAlias" and react on it. (but I've never done a thing like this)


I would like to write a Script that can vary it's logic based on what session it is running under.

How  can I get the current session name or title?

Thanks,

Mark Hecht


#Rumba

Almost surely I'm wrong but the in some of my script I use:

' Get Current Alias of the connection

EMGetCurrentAlias CurrentAlias

' Connect to the current terminal

EMConnect CurrentAlias

to be sure to use the right connection as I use multiple script running at the same time, maybe you can parse the "CurrentAlias" and react on it. (but I've never done a thing like this)


I would like to write a Script that can vary it's logic based on what session it is running under.

How  can I get the current session name or title?

Thanks,

Mark Hecht


#Rumba

Hi cberetta,

I take it back :-)

you are correct, you can assign an alias to a session and "activate" it. The "activation" does not set the keyboard or mouse input focus to a session, it makes it the "active" EM session, i.e. the one which the various EMxxxx methods talk to.

Here is a sample macro to demonstrate.

Sub Main

Dim CurrentAlias As String  

EMAssignAlias "Dallas1", "D1"  

EMAssignAlias "Dallas2", "D2"

EMConnect "D1"

EMSendKey "Dallas1"

EMGetCurrentAlias CurrentAlias

Msgbox CurrentAlias

EMConnect "D2"

EMSendKey "Dallas2"

EMGetCurrentAlias CurrentAlias

Msgbox CurrentAlias

End Sub

In the above I have two sessions open Dallas1 and Dallas2, I assing D1 to Dallas1 and D2 to Dallas2.

Next I click on the Dallas2 session in my Rumba workspace, then I run the macro. I don't see any switch of focus in the workspace, however the EM focus does switch, D1 is activated and "Dallas1" written to it, then D2 is activated and "Dallas2" is written to it.  The EMGetCurrentAlias also works as you will see via the message boxes.

Note: It looks like you have to assign the "alias" at macro runtime, i.e. you can't assign it in one macro and then in a subsequent macro use EMGetCurrentAlias to read it back.

Very nice, thanks for pointing this out to me.

Tom


I would like to write a Script that can vary it's logic based on what session it is running under.

How  can I get the current session name or title?

Thanks,

Mark Hecht


#Rumba

Both of these get the info, but the Windows API solution is the only one that works in my specific case. I am trying to write a login script that varies it's logic based on the session name. It's no help to me if the script has to set the alias before it can retrieve it.