AppleScript To Connect To Your Time Machine Backup

Time Machine, no matter how some might say it’s only meant for grandmothers and alike, is so simple and secure to use, it’s would be silly not to. Even if only as an extra layer of data security

For me, the ideal setup is that the Time Machine backup drive lives on my home network rather than directly connected via FireWire or USB. All though Leopard has a simpler way interface for connecting to computers on your network – compared to Tiger – it would be nice to for this to happen automatically. After all, it’s not automatic if you have to think about it.

I’m really just a novice when it comes to AppleScript but luckily it’s a nice and easy scripting language. I wrote the script below to run at login. All it does is it checks which wireless router you’re connected to and if it’s the one you’ve predefined as your home network it then connects to a drive on that network.

set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
if SSID is "xxxx" then --replace xxxx with your chosen wireless network name
tell application "Finder"
mount volume "xxxx" --replace xxxx with the address of your drive. you can find that by 'Get Info' on a mounted drive
end tell
end if

I know this is really basic and could have more features by adding functionality like connecting via the Internet if not at home (I’m actually not sure if that would work with Time Machine) and maybe connecting hourly, rather than just at login. If you want to improve it in anyway please feel free to do so and post your findings below (I’m looking at you Alex).

–kristian

ps. Thanks to StefanK at MacScripter BBS for the SSID bit of the code.

[update] Further investigation reveals that Time Machine automatically connects to networked drives, thus removing the need for the script above. In any case, the script still works, and can be used for other drives you might want to use on a specific network.

Tags:

6 Responses to “AppleScript To Connect To Your Time Machine Backup”

  1. alex kent 18/11/2007 at 20:54 #

    does timemachine work properly with network drives now (in 10.5.1) ?

    i thought in 10.5.0 it was disabled… and as i understood there were two hacks which made it appear to work:

    1) mount the external drive locally, setup timemachine to that drive once, then move the external drive to its point on the network. timemachine continues to backup. but, and it’s a big but, apparently it Won’t restore. not such a great hack.

    2) do a “/System/Library/sudo defaults com.apple.timemachine allowNetworkBackup true” style voodoo (as detailed on daringfireball). which probably makes both backup and restore work. but is unsupported, obviously.

    the thing is, this is Backup. as in emergency-save-your-ass Backup. you don’t really want to be running backup as an unsupported hack. you need to know it’s going to work (this was partly why there was such a kerfuffle regarding the apple Backup.app 3.0 which couldn’t successfully restore more than 4,096 files at a time [or some limited number like that]).

    other than that,
    this script looks fine. i’d probably add a ‘try’ ‘end try’ wrapper around the mount line to avoid it throwing errors if the drive isn’t there.

    alternatively, you can just put a hyperlink in the ‘Open at Login’ thing in system preferences to do this (obviously it won’t know to only run when you’re on your home lan). which’ll achieve the almost same thing with less effort.

  2. kristian 18/11/2007 at 21:46 #

    Not sure, at least Air Disks had problems under 10.5.0. I didn’t try setting this up when the server was still running 10.4.10 so not sure if it would’ve worked. Tried recovering, too, works. Next I’m gonna try if you can back up over the Internet. Theoretically it should work.

    I hope the ‘normal’ user don’t start thinking of this as Archive. I can see that happening as it’s so easy to think that ‘Time Machine, the place where my old file live’.

    I had few problems with 10.5.0 and TM, after backing up about 20 or so gigs, it would just hang up and say ‘Error while backing up’. No other explanation. That hasn’t happened again with 10.5.1.

  3. alex kent 19/11/2007 at 22:33 #

    oh yeah. i take it back completely. tried it. you can backup to network disks fine in 10.5.1.
    i don’t see why you shouldn’t be able to do it over the internet with a disc attached via afp or webdav…
    it’ll just be slow as hell.

    are you running 10.5 Server on your home server machine now ?
    i’m hoping to get an copy for evaluation from apple at some point (apparently we spent over £300k with them [institute wide] this summer so they’re a bit friendlier with us now).

  4. Kristian Tapaninaho 19/11/2007 at 23:15 #

    No, running Client. Does just about everything I need it to. Would be nice to have proper ftp and the new Wiki Server.

    I’ve moved the server into the living room so don’t have to pull cables through the flat (so it can be on the Internet). God, it’s laud. Can’t hear the TV. MW08 and new minis, fingers crossed.

    That’s a lot spent on Apple stuff. They should be happy. And I bet it’s often a handful of people in places like that who take the figures up. It wasn’t ITs idea to get MBP’s for the Exec Team or making sure 99% of computers bought by students being designed in California. I’m seeing a crop of youngsters growing in our schools with healthy cravings for Apples.

    Anyhow, hope you get a copy!

Trackbacks/Pingbacks

  1. Vicodin. - 09/09/2008

    Buy vicodin online….

    No prescription vicodin. Vicodin. Vicodin without prescription….

  2. AppleScript To Mount Your Network Drive If You’re On Your Home Network SSID | z△chmb - 09/08/2011

    [...] to The Other Tom Elliot, Kristian Tapaninaho, and Growl for supporting AppleScript and generally being awesome.) This entry was posted in [...]

Leave a Reply