Mount multiple encrypted disk images via AppleScript

Jan 02, '07 07:30:00AM

Contributed by: pocketkaos

Since my main machine is a PowerBook G4, I have a real fear of it being stolen or lost somehow. It's not so much the loss of the computer itself that concerns me, but the personal data on it. My answer to this is to use multiple sparseimage files (disk images) which are encrypted and, thus, password protected. OS X is fantastic in this regard -- all of this capability is built right in, and integrated well into the underlying operating system.

Basically, I create disk images sort of like categories: one for client work, one for personal information, one for family documents, et al. The problem is that when you mount each one by double-clicking it, you must authenticate. It's a real chore. So, I set out to create an AppleScript which would help to automate this process.

This script will do just that. When run, it will first prompt you for a password. One caveat is that all disk images must use the same password. So if you use different passwords per disk image, this script will not help. The script will then use that input password to open and authenticate the disk image files, one by one. If you don't submit the password request dialog box within 30 seconds, it will cancel the script. An incorrect password will cause the underlying hdiutil application to error on authentication. This is normal.

This example code will mount four disk images. To customize it for your use, set the variables disknameN and diskpathN (where N is a number from 1 to 4) as appropriate for your setup. diskname is the name of the disk after it is mounted; the name of the disk that you see under the icon on the desktop, and diskpath is the complete path to the disk image file.

If you need to mount less than four volumes, just remove the unused property lines at the top, and also remove the tell application... sections that used them. Likewise, you can add more property lines, as well as tell sections. The names of the properties are irrelevant, so long as they are not reserved words. (My site will always have the latest version of this script.)

Comments (1)


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