Page 1 of 1

AppleScript and Coolterm

PostPosted: Mon Jun 22, 2020 2:35 pm
by Serge58
Hello,

First of all, thank you for the Coolterm software. And also thank you for redirecting me unintentionally to Xojo. I have been using Delphi for years until it went out, and have been using Lazarus since then but I don't like it anymore. The Mac installation and distribution is not very user friendly and I was very pleased to discover Xojo which I will investigate furthermore.

I have an issue with Coolterm and Applescript and I can't find an example that will help me in the provided documentation.

I need a simple script that will send text to the serial port through Coolterm. I am using a Mac and want to send text to an arduino via an AppleScript. I can do it directly using Coolterm but I can't figure it out using AppleScript. And Coolterm needs to stay invisible.

Is that possible? help needed please.
Thanks,

Re: AppleScript and Coolterm

PostPosted: Tue Jun 23, 2020 9:12 pm
by roger
Hi,

here is an example that sends a text file:

Code: Select all
tell application "CoolTerm"
   
   set Filepath to "/Users/Shared/textfile.txt"  # replace this with the path to your file
   
   # 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

Re: AppleScript and Coolterm

PostPosted: Wed Jun 24, 2020 9:02 am
by Serge58
Many thanks,
That will be a big help/

regards,

Re: AppleScript and Coolterm

PostPosted: Fri Jun 26, 2020 6:38 am
by Serge58
It was a big help.

Is there a way to keep the Coolterm window invisible?
Running in the background?

thanks,

regards,

Re: AppleScript and Coolterm

PostPosted: Fri Jun 26, 2020 7:28 pm
by roger
Serge58 wrote:Is there a way to keep the Coolterm window invisible?
Running in the background?


There is, sort of. It's the progress window that opens when you're sending a file that brings the CoolTerm window out of hiding. However, there is a trick you can use to keep the progress window from appearing. CoolTerm transmits text files in packets (i.e. chunks of a specific size). When there is more data than fits into this packet size, CoolTerm chops it up into multiple such packets. That's when the send progress window appears. But if you send less than the packet size, the window doesn't open. If you know the size of your text file (in bytes), you can set the transmit packet size (in the connection setting, under "Transmit/Transmit Options/Transmit Packet Size) to something just a little larger than the size of your files. For example, if your file is 10,000 bytes long, then set the transmit packet size to something larger than that (e.g. 10,100), and the send status window will no longer appear when you send your text files. Thus, if you hide CoolTerm and run your AppleScript to send your text file every few minutes, CoolTerm will stay hidden.