It’s All About Control

    So here is how it works. I can control my super audio electronics and other various devices around the house with this page (from anywhere in the world). This page has pre-loaded commands set in the subject line of emails, when one clicks the links below. My mail application, (Mail, OSx) is set to run different scripts (Apple-Scripts) for different pre-loaded email subjects when they are received. They in turn, invoke the screen program (UNIX) from within the terminal application. This sends serial data to my home-brew mbed (www.mbed.org) computer.



Here is an example of the Apple-Script (and UNIX Bourn Again Shell Script embedded) that runs the terminal application and the ‘screen’ program. 


tell application "System Events"

tell application "Terminal" to activate

keystroke "screen /dev/tty.usbmodem0000101D2 38400" & return

delay 1


tell application "Terminal" to activate

keystroke "lightshow" & return


delay 2

end tell


What this is doing, is giving commands (like actual keys being pressed (keystroke)) to the window that is on top (we make sure that “Terminal” is on top by saying ‘activate’). Then we tell the shell program ‘screen’ to open a connection to /dev/tty.usbmodem0000101D2 (this is what my device is called and it can change) at 38400 baud, and hit return. It delays a second to give time for the devices to connect, then it types “lightshow” into the screen program (this is a command that gives a light show in my house when my computer receives the word lightshow). I use this command so I know when I have connected. I could have made one gigantic script to read the subject line, that would probably have been a better way to do it, but I didn’t.


Here is an example of the code for the ‘about’ function on the mbed, it gives the user a txt file response in a reply email:


tell application "System Events"

tell application "Terminal" to activate

keystroke "about" & return

delay 1

keystroke "a" using control down

keystroke "h"

keystroke "n" using command down

keystroke "mv hardcopy.0 hardcopy.txt" & return

delay 0.6

end tell

tell application "System Events"

tell application "Mail" to activate


delay 0.7

keystroke "r" using command down

delay 0.7

keystroke "A" using command down

delay 0.7

keystroke "/"

delay 0.2

keystroke "Users/BrainLube/hardcopy.txt"

delay 0.5

key code 76

key code 76

key code 76

key code 76

key code 76

delay 0.2

key code 76

key code 76

key code 76

key code 76

key code 76

delay 1

keystroke return

delay 1

keystroke "D" using command down


end tell

tell application "System Events"

delay 1

tell application "Terminal" to activate

keystroke "rm hardcopy.txt" & return

delay 1

keystroke "w" using command down


end tell


THIS is the one I ended up using, it sends a txt file to the website so people my view the status in a file named hardcopy.txt. (www.brainlubeonline.com/hardcopy.txt)


tell application "System Events"

tell application "Terminal" to activate

keystroke "about" & return

delay 1

keystroke "a" using control down

keystroke "h"

keystroke "n" using command down

keystroke "mv hardcopy.0 hardcopy.txt" & return

keystroke "ftp ftp.brainlubeonline.com" & return

delay 2

keystroke "UserName" & return

delay 2

keystroke "Password" & return

delay 2

keystroke "cd brainlubeonline.com" & return

delay 1

keystroke "send hardcopy.txt" & return

delay 3

keystroke "close" & return

delay 0.5

keystroke "quit" & return

delay 0.5

keystroke "rm hardcopy.txt" & return

delay 1

keystroke "w" using command down



end tell

Tempmailto:alexandermcalpine@gmail.com?subject=BLO Command: temp
Aboutmailto:alexandermcalpine@gmail.com?subject=BLO Command: about
Command Listmailto:alexandermcalpine@gmail.com?subject=BLO Command: cmdlst
GoCommmailto:alexandermcalpine@gmail.com?subject=BLO Command: GoComm
Helpmailto:alexandermcalpine@gmail.com?subject=BLO Command: help
LED Snakemailto:alexandermcalpine@gmail.com?subject=BLO Command: ledsnake
Light Showmailto:alexandermcalpine@gmail.com?subject=BLO Command: lightshow
Refresh (LCD Display)mailto:alexandermcalpine@gmail.com?subject=BLO Command: refresh
Clear Screen (Terminal)mailto:alexandermcalpine@gmail.com?subject=BLO Command: clear
Power On Receivermailto:alexandermcalpine@gmail.com?subject=BLO Command: power1
Volume Upmailto:alexandermcalpine@gmail.com?subject=BLO Command: upvol
Volume Downmailto:alexandermcalpine@gmail.com?subject=BLO Command: downvol
Get Receiver Informationmailto:alexandermcalpine@gmail.com?subject=BLO Command: rcvrStat
AUX 1mailto:alexandermcalpine@gmail.com?subject=BLO Command: aux1
AUX 2mailto:alexandermcalpine@gmail.com?subject=BLO Command: aux2
AUX 3mailto:alexandermcalpine@gmail.com?subject=BLO Command: aux3
AUX 4mailto:alexandermcalpine@gmail.com?subject=BLO Command: aux4
AUX 5mailto:alexandermcalpine@gmail.com?subject=BLO Command: aux5
AUX 6mailto:alexandermcalpine@gmail.com?subject=BLO Command: aux6
Power Off Receivermailto:alexandermcalpine@gmail.com?subject=BLO Command: power0
Back to www.BrainLubeOnline.comhttp://www.BrainLubeOnline.comhttp://www.brainlubeonline.comshapeimage_22_link_0
 

HomeBrew Computer Status