Remote Mac Control
I need to help out my grandmother with her mac occasionally. Now it’s much easier if I can just VNC straight into her machine. Unfortunately, it’s behind a router. But that’s OK. As usual, ssh tunnels to the rescue.
Unfortunately, she’s not really capable of using the command line. So it’s out with the AppleScript!
I wanted a little icon she could click to set up an ssh tunnel. That tunnel should then be torn down when the app closes. This is what I ended up with.
global pid on run set sshCmd to "ssh -i ~/.ssh/vnc happygiraffe.net -R 5900:localhost:5900 -N" set pid to (do shell script sshCmd & "</dev/null >/dev/null 2>&1 & echo $!") display dialog "Connected to happygiraffe.net" end run on quit do shell script "kill " & pid continue quit end quit
There’s a few interesting points about this.
- You have to redirect stdin/stdout/stderr to
do shell scriptwill never return.
- I didn’t realise, but you capture the output of
do shell scriptby enclosing it in parentheses. Yes, this is basic AppleScript. but it’s all new to me.
on quithandlers let you do
Save As...application bundle. So you end up with a clickable application.
on quitmust call
continue quitor you end up with an immortal app…
- The ssh command itself has a couple of interesting features.
-i ~/.ssh/vncuses a custom key that I set up, instead of having to rely on a password.
-R 5900:localhost:5900forwards port 5900 on happygiraffe.net back to port 5900 on her computer.
-Nmeans “do nothing” instead of firing up some shell on my server.
At some point, I might extend this so that there’s a Window with a connect / disconnect button. But that will involve AppleScript Studio, which I don’t have on this computer.
So now I should be able to help clear up any, errr, “incidents”. Hopefully.
If you’ve more than one computer at your desk, and one of them is a Mac, you need osx2x. It lets you use all the other computers via VNC or X-Windows connections, using only the one mouse and keyboard. Shiny.
Sadly, the download link on the main site is broken. This is a bit of a pain as it doesn’t appear to be mirrored anywhere.
Luckily, I found one chap who had created a fresh distribution from the (still available) source: osx2x Mac OS 10.4 (Tiger) Universal Binary. I’ve installed that version and it’s working great. My sincere thanks to jamesotron.
Update: Annoyingly, I can’t figure out how to right click when talking to the windows box. That’s a bit annoying.