Easily mount disk images with an AppleScript

Jun 06, '02 09:20:37AM

Contributed by: Gwenhiver

Here's a trick I discovered a few weeks ago. It basically wraps a shell command into AppleScript to ease disk image mounting. Here's the translation of what I published on my French website...

Under Mac OS X, disk image processing is provided by a private framework: DiskImages.framework (in /System -> Library -> PrivateFrameworks -> DiskImages.framework). Thanks to this framework, you can burn a CD directly from the Finder. In the Terminal, hdiutil is used to communicate with it. You can, for example, mount a disk image typing:

hdiutil mount disk_image_name.dmg
What's the point? Just try it. Instead of having Disk Copy launch, mount the image, and then quit, hdiutil provides you with a seamless integration of disk image mounting without any app-launching.

Now, sure, it isn't great to go to the Terminal each time you need to mount a disk image. So let's make an AppleScript wrapper for this command:
tell application "Finder" to set filelist to selection as list

repeat with aFile in filelist
if ((aFile as string) ends with ".dmg") then
do shell script ("hdiutil mount \"" & ¬
POSIX path of (aFile as string) & "\"")
end if
end repeat
Just save the script as a compiled script, and put it in ~/Library/Scripts if you use Apple's ScriptMenu (and want to use it from the menubar), or in ~/Library/Big Cat Scripts/Files if you use Big Cat (and want it to appear in the Finder's contextual menu), or wherever you wish if you use Key Xing (and want to launch it from the keyboard). You'll just have to select any number of disk images in the Finder and launch the script. You'll be done very fast.

(For those who prefer to use SNAX, there is currently no way to use this script. SNAX doesn't load Big Cat's contextual menu, and version 1.2.8 is unable to provide a list of selected items anyways. Steve Gehrman, SNAX's author, is aware of the problem and will try to fix it in the next version.)

Comments (2)


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