View Single Post
  #1  
Old 02-20-2005, 04:22 PM
kbradnam kbradnam is offline
Registered User
 
Join Date: Feb 2005
Location: Davis, CA
Posts: 25
An (Applescript) hack to automate mounting and unmounting external volumes

My problem (see the other thread of mine) is that when you launch SuperDuper!, it 'remembers' the drives it last backed up to. So if you last backed up to an external drive that is currently not plugged in or mounted, you have to click 'Cancel' when SuperDuper reports that it can't find external drive 'XYZ'.

This has caused me some problems when trying to automate our backups as the backup scripts don't get past the 'Cancel' button and so they just sit there and wait.

Another problem I have is that I use an external firewire drive which contains two disk images (created as sparse images so that I can run Smart Update). SuperDuper can automatically mount these disk images but only if the external drive itself is first mounted. There are reasons why I think it is not always good to keep an external drive mounted when it is not in use. Also I've noticed that SuperDuper does not unmount the mounted disk images when it has finished backing up.

So on Friday I tried learning some Applescript to amend the basic Daily Backup script. My daily backup script now has the following at the start of the script:


Property diskname : "External HD"

tell application "Finder"
if not (exists the disk diskname) then
do shell script "diskutil mount `disktool -l | grep 'External HD' | sed 's/.*\\(disk[0-9s]*\\).*/\\1/'`"
delay 1
end if
end tell

delay 2


This uses the UNIX 'disktool' command to find out (with some sed and grep hacks) which device our firewire drive is connected to (will usually be disk2 or disk3 depending on how many other drives are connected). It then passes this disk name to the diskutil command to mount that volume.

I then include the rest of the SuperDuper script which is then followed by the next piece of code:


delay 2

tell application "Finder"
if (exists the disk "local_home_backup") then
eject "local_home_backup"
delay 2
end if
eject "External HD"
end tell



This ejects the disk image that was mounted for the backup and then ejects the volume as well. If you have multiple disk images on a volume, you may need to add extra lines in this section to first eject all of the disk images that may be mounted (SuperDuper can mount all images on an external volume...or at least all of those that you have ever backed up to). You won't be able to eject the firewire disk without first ejecting *all* mounted volumes on it.

This hack now means that I can automate our nightly backups without worrying about SuperDuper asking for a particular disk image to be mounted. It also means that when the backup finishes the external disk is unmounted.

Hope this might be useful to someone else.

Keith

P.S. This is my first ever attempt at using AppleScript, I'm sure there are better/neater ways of doing this.[FONT=Century Gothic]
Reply With Quote