Unmount a volume (on login) via AppleScript

Feb 23, '06 05:57:00AM

Contributed by: claudio

I was looking for a way to unmount a volume which appears on the Desktop immediately after logging in Mac OS X 10.4 (Tiger) for security reasons (it's a rescue volume with a plain system on it), and came across this hint from Norm Nager: A script to unmount cloned backup volumes at login.

All attempts to use Norm's script failed for me. I have no idea why, so I tried something else. Even with Automator, it did not work, so I ended up with this little AppleScript:

tell application "Terminal"
  activate
  do script ¬
   "diskutil unmount \"/Volumes/volumename to unmount\"" in ¬
   window frontmost
  delay 5
  quit
end tell
It activates Terminal, invokes Apple's command line tool diskutil in the frontmost window of the Terminal app, unmounts the Volume with the name Volumename to unmount, waits five seconds (until the unmount progress is finished, otherwise a sheet opens and asks for user interaction, which is very inconvenient), and then quits the Terminal.

The script works fine for users with administrator accounts, but standard accounts do have to enter an admin name and admin password. So it's not an all-rounder. If there is anyone who has an idea how to unmount volumes in Tiger while logging in as a standard user, please help me.

Comments (14)


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