Securely run remote AppleScripts

Nov 01, '01 02:44:36AM

Contributed by: rajiv

normally with ssh you can run (on the command line) 'ssh machine command' to run a command on a remote machine. so put a compiled applescript called 'testscript' in your home directory and try and run it from a remote (or even the local) machine:

ssh yourmac testscript
and it will run that applescript. however, while that applescript shows up in the dock, it seems to have no access to running processes.

the trick is on the remote machine to run:
ssh yourmac 'open testscript'
the command above will instruct the running finder process to launch the applescript. see also the macosxhint Run an AppleScript from the command line and running applescripts via ssh? at macfixitforums.

for an example of a useful remote applescript (launch eudora and get new mail only when new mail exists), read the rest of the article.

Remote Eudora mail checking AppleScript:

tell application "Finder" to get creator type of every process
if result contains "CSOm" or result contains «class CSOm» then
tell application "Eudora 5.1 (OS X)"
connect with checking without sending and waiting
end tell
end if
i use the above applescript along with this in my .qmail file on my linux box to tell eudora to check mail only when i actually get new mail:
./Mailbox
|ssh mymac 'open /Users/rajiv/CheckMail.app'
now, anyone know how to pass information to and receive from the applescript? no matter how the applescript exits (you can even put in a 'return' or and 'exit' statement in the script), the ssh command will always return 0 if the script was able to run.

Comments (1)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20011101024436520