Page 1 of 1

CoolTerm Macros using AppleScript

PostPosted: Mon Apr 23, 2018 9:43 pm
by roger
While AppleScript doesn't support fancy GUIs, it does support simple dialogs. The following script can be used to create transmit macros for CoolTerm:
Code: Select all
tell application "CoolTerm"
   
   # Get a handle on the open window.
   set w to WindowID (0)
   if w < 0 then
      # there are no open windows
      display alert "There are no active terminals"
      return
   end if
   
   repeat
      # display a dialog with buttons
      choose from list {"Marco Text 1", "Macro Text 2", "Macro Text 3"} with prompt "Please select Macro and click OK to send."
      if the result is not false then
         # send macro to CoolTerm
         set macro to result as text
         Write {w, macro}
      else
         # user clicked "cancel"
         return
      end if
   end repeat
   
end tell
The script creates a dialog with a list of strings and allows the user to select a string from the list and then send it to CoolTerm by pressing the OK button. As long as OK is pressed, the script stays in the "repeat" loop which will keep displaying the dialog. This is a bit of a hack which is necessary because pressing any of the buttons closes the dialog. However, this does the job. Pressing "Cancel" exits the loop and terminates the script.
CoolTerm_Macro.png