Skip to content

Instantly share code, notes, and snippets.

@justincjahn
Created April 3, 2012 18:51
Show Gist options
  • Save justincjahn/2294631 to your computer and use it in GitHub Desktop.
Save justincjahn/2294631 to your computer and use it in GitHub Desktop.
GUI for serial connections.
tell me
# Focus the windows we are about to make
activate
#
# Ask the user what device they would like to use.
#
set strSerialDevices to (do shell script "ls /dev/tty.*")
set listDevices to (paragraphs of strSerialDevices) as list
set strDevice to (choose from list listDevices with prompt "Select Device:")
# Make sure they selected a value
if strDevice = false then
return
end if
#
# BAUD RATE
#
display dialog "Select Baud: (9600, 38400, 115200, ...)" default answer "9600"
set intBaud to text returned of result
# Make sure they selected a value
if intBaud = false then
return
end if
#
# CHARACTER SIZE
#
set lSize to {"cs5", "cs6", "cs7", "cs8"}
set sSize to choose from list lSize with prompt "Character Size" default items {"cs8"}
# Make sure they selected a value
if sSize = false then
return
end if
#
# STOP BITS
#
set lStop to {"One", "Two"}
set sStop to choose from list lStop with prompt Â
"Stop Bits" default items {"One"}
if sStop = false then
return
else if sStop = {"One"} then
set sStop to ",-cstopb"
else if sStop = {"Two"} then
set sStop to ",cstopb"
else
set sStop to ""
end if
#
# FLOW CONTROL
#
set lFlow to {"Enabled", "Disabled"}
set sFlow to choose from list lFlow with prompt Â
"Flow Control" default items {"Disabled"}
# Make sure they selected a a value
if sFlow = false then
return
else if sFlow = {"Disabled"} then
set sFlow to "-crtscts"
else
set sFlow to "crtscts"
end if
#
# PARITY
#
set lParity to {"None", "Even", "Odd"}
set sParity to choose from list lParity with prompt Â
"Parity" default items {"None"}
# Make sure they selected a a value
if sParity = false then
return
else if sParity = {"None"} then
set sParity to "-parity"
else if sParity = {"Even"} then
set sParity to "parity"
else
set sParity to "oddp"
end if
#
# Check .screenrc for the termcapinfo option.
#
# Open the user's RC file
set strFile to ((path to current user folder) as string) & ".screenrc"
# If the file doesn't exist, this will cause an error.
## Create a new, blank screenrc in order to proceed.
try
read file strFile as {text}
on error
do shell script "echo '# Automatically created with SerialConsole' > ~/.screenrc"
end try
# Read the configuration file.
read file strFile as {text}
set strScreenRc to result
# Check the file's contents, and add our configuration if
## it does not exist already.
set strCheck to "termcapinfo xterm* ti@:te@"
if strScreenRc does not contain strCheck then
do shell script "echo " & strCheck & " >> ~/.screenrc"
end if
end tell
#
# Open the terminal, make a new tab and run screen
#
tell application "Terminal"
# Focus the first terminal window
activate window 1
# Create a new tab
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
# Run the command in our newly created window
do script with command Â
"screen -A -a -h 1000" & Â
" " & strDevice & Â
" " & intBaud & Â
"" & sStop & Â
"," & sFlow & Â
"," & sSize & Â
"," & sParity Â
in window 1
#set number of rows of window 1 to 100
#set number of columns of window 1 to 80
set background color of window 1 to "black"
set normal text color of window 1 to "white"
set custom title of window 1 to "Serial Connection"
# Display the dialog.
display dialog "To quit your terminal session type <Ctrl-A> then <Ctrl-\\>." buttons {"Ok"} default button "Ok"
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment