Tags

, , ,

In my previous post, I used AppleScript and Alfred to automate the opening of two serial monitors on my Mac to aid in debugging send/receive RF traffic.

I have two work environments and found myself modifying the script when I moved to the other work environment.  One is a desk / treadmill which I use in the AM. By the PM my legs are weary so I move to a desk setup. Each environment uses a different serial port.  Every scripting language I have ever used allowed for user input.  So off to Google and (another YIPPEE! moment) I enhanced the AppleScript to allow me to input a different serial port.

tell application "Terminal"
display dialog "Enter the serial port" default answer "usbmodemfa131"
set theSerialPort to (text returned of result)
-- display dialog "The Serial port is " & theSerialPort
-- display dialog "Enter the baud rate" default answer "57600"
-- set theBaudRate to (text returned of result)
-- display dialog "The Baud rate is " & theBaudRate
set theScreenCmd to "screen -t \\" & theSerialPort & "\\\" /dev/tty." & theSerialPort & " 57600" as text
-- display dialog "The screen command: " & theScreenCmd
activate
try
do script with command theScreenCmd
on error
display dialog "There was an error with the screen command" buttons {"Okay"} default button 1
end try

I highlighted the most important changes in red. I commented out the lines referring to other variables – like the baud rate – so that you could feel comfortable with adding whatever variables you needed. I don’t need a robust solution since I am the only one using it. This solution adds at its best one more click. For now that outweighs having to edit the script when I change work environments.

Advertisements