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.
One reply on “Remote Mac Control”
Drat. When I actually try it, VNC doesn’t work. Which reminds me, I should have changed sshCmd to include