AppleScript and Coolterm

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

AppleScript and Coolterm

Postby Serge58 » Mon Jun 22, 2020 2:35 pm

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,
Serge58
 
Posts: 3
Joined: Mon Jun 22, 2020 1:25 pm

Re: AppleScript and Coolterm

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

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
User avatar
roger
Site Admin
 
Posts: 241
Joined: Fri Apr 24, 2009 12:41 am

Re: AppleScript and Coolterm

Postby Serge58 » Wed Jun 24, 2020 9:02 am

Many thanks,
That will be a big help/

regards,
Serge58
 
Posts: 3
Joined: Mon Jun 22, 2020 1:25 pm

Re: AppleScript and Coolterm

Postby Serge58 » Fri Jun 26, 2020 6:38 am

It was a big help.

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

thanks,

regards,
Serge58
 
Posts: 3
Joined: Mon Jun 22, 2020 1:25 pm

Re: AppleScript and Coolterm

Postby roger » Fri Jun 26, 2020 7:28 pm

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 is 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.
User avatar
roger
Site Admin
 
Posts: 241
Joined: Fri Apr 24, 2009 12:41 am


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron