The ID is a unique handle that CoolTerm assigns to a terminal window when it is first opened. This handle remains the same for as long as CoolTerm is running. Even if a window is closed, CoolTerm will not reuse the ID of that window as long as the CoolTerm app is running. The handle allows CoolTerm to access a specific terminal window
The ID is not the same as the index of the window. The index is merely the number of the window in the list of open windows. If there are N open windows, the indices of the open window range from 0..N-1, and the numbers are in the order in which the windows were opened. The window with index 0 is always the window that has been opened the longest. If that window closes, then the window that previously had index 1 now has index 0.
Thus, it's important that the first thing every script does is to get the ID for the window it needs to access. If there is only one window, then the index of that window is always 0, and when you know the index of the window you want to access, you can get a handle this way:
Code: Select all
----------------------------------------------------------------------------
WindowID(Index as integer) as integer
----------------------------------------------------------------------------
Returns the ID of the window with the specified index.
Returns -1 if the window doesn't exist.
If you don't know the index of the window, then you can look it up with its name if you know it, like this:
Code: Select all
----------------------------------------------------------------------------
WindowIDfromName(WindowName as String) as integer
----------------------------------------------------------------------------
Returns the ID of the window with the specified name.
Returns -1 if the window doesn't exist.
E.g.: # Get the ID of the terminal Window named "Untitled_0".
Set WinID to WindowIDfromName ("Untitled_0")
Here is a simple script you can use to create a list of all open terminal windows:
Code: Select all
# Display the IDs of all terminal windows
set winList to {}
set n to WindowCount
repeat with i from 0 to n - 1
set WinID to WindowID (i)
set WinName to WindowName (i)
copy ("Index: " & i & ", ID: " & WinID & ", Name: " & WinName) to the end of winList
end repeat
winList
I hope this clarifies it.