CoolTerm Script for Periodic Polling

If you have specific questions or problems with any of my Freeware applications, post them here.

CoolTerm Script for Periodic Polling

Postby erikj » Mon Jun 22, 2020 3:21 pm

Howdy Roger,

I'm new to Mac and am still learning AppleScript. I have some CS background but I'm trying to get ahead of a router issue.

I have a text file for some command lines to the router. I can successfully send the te4xt file (CT_Debug_Script.txt) to the serial port successfully to pull data that I'm logging. What I'd like to do is have CoolTerm do this automatically, say every 5 to to minutes.

I was a bit puzzled on the SendTextFile syntax, so I only have this so far:

Code: Select all
tell apllication "CoolTerm"

   SendTextFile(1, /Users/zyxeltest/Desktop/EX5510 Console Logs/CT_Debug_Script.txt) 1

end tell


I know this isn't right, I probably have to assign local variables to the window like you mentioned here, but I'm also wondering if I can create an empty if loop and set a delay for 300 seconds, for example, and then tell the script to terminate when I close the window.

I've had some experience with Terra Term scripting, but AppleScript is new ti me. Thanks for any help you can provide.
erikj
 
Posts: 2
Joined: Mon Jun 22, 2020 3:10 pm

Re: CoolTerm Script for Periodic Polling

Postby roger » Tue Jun 23, 2020 9:05 pm

Hi,

here is an example that sends a text file:

Code: Select all
tell application "CoolTerm"
   
   set Filepath to "/Users/Shared/textfile.txt"
   
   # Get the ID of the first open window
   set WinID to WindowID (0)
   if WinID < 0 then
      display alert "No open windows"
      return
   end if
   
   # Open the serial port
   if not (Connect WinID) then
      display alert ("Not Connected")
      return
   end if
   
   # Send the file
   set success to SendTextFile {WinID, Filepath}
   if success is not true then
      display alert "Error opening text file."
      return
   end if
   
   # Wait until it's done sending
   repeat until (BytesLeftToSend (WinID)) <= 0
      Poll (WinID)
      delay 0.2
   end repeat
   
   display alert ("Done sending!")
   
end tell


To send the file repeatedly ever 5 minutes, you change the script as follows:

Code: Select all
tell application "CoolTerm"
   
   set Filepath to "/Users/Shared/textfile.txt"
   
   # Get the ID of the first open window
   set WinID to WindowID (0)
   if WinID < 0 then
      display alert "No open windows"
      return
   end if
   
   # Open the serial port
   if not (Connect WinID) then
      display alert ("Not Connected")
      return
   end if
   
   repeat
      # Send the file
      set success to SendTextFile {WinID, Filepath}
      if success is not true then
         display alert "Error opening text file."
         return
      end if
      
      # Wait until it's done sending
      repeat until (BytesLeftToSend (WinID)) <= 0
         Poll (WinID)
         delay 0.2
      end repeat
      
      # wait for 5 minutes
      delay 300
   end repeat
   
end tell
User avatar
roger
Site Admin
 
Posts: 241
Joined: Fri Apr 24, 2009 12:41 am

Re: CoolTerm Script for Periodic Polling

Postby erikj » Tue Jun 23, 2020 10:15 pm

Thanks! One of my questions is what the ID was for; I figured it was the ID of the window for multiple instances, but I wasn't sure how to find said ID.

My thanks, this will go a long way towards helping me understand AppleScript and getting this periodic check up and running.
erikj
 
Posts: 2
Joined: Mon Jun 22, 2020 3:10 pm


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron