Applescript to unmount stubborn volumes

I’ve been frustrated recently because external hard drives connected to my MacBook have refused to unmount. After resorting to restarting before trying again, I posted my problem to a number of online forums.

Knowledgeable member of the Macworld forums oddlot answered my question with a Unix command called hdiutil that can force eject a drive.

I took this command and wrote a quick Applescript that displays a list of the connected drives and force ejects the one you choose.

I linked this up to a Butler trigger, so now if a drive is uncooperative, I can activate this script with one key combination.

If you wish to use this script as a simple application, copy the code listed into a Script Editor window (found in /Applications/Applescript). You’ll likely not need to change anything, but if your startup disk is anything other than Macintosh HD, you need to change the beginning variable startupDisk. Choose Save As from the File menu and pick Application from the dropdown menu. This will create an application that you can easily double click whenever you need it.

UPDATE: I realized after I posted this that the functionality is broken when the disk contains spaces in the name. The code posted here has been corrected.
[tags]Applescript, Automator, programming[/tags]

Tagged with: , , , , ,
5 comments on “Applescript to unmount stubborn volumes
  1. Ive Tried It And No Luck

  2. wesg says:

    @Connor Phifer: Thanks for trying it, I’ll check it again.

  3. david says:

    Great program. I tried every possible approach to unmount my removable HD. This app worked flawlessly and effectively by the click of the mouse. Many thanks to the author!

  4. TJ says:

    Exactly what I needed. Simple and perfect. Thank you!

  5. Jim Tanner says:

    if you replace line 26

    -> do shell script “hdiutil eject -force /Volumes/” & theText do shell script “hdiutil eject -force /Volumes/” & “‘” & theText & “‘” <-

    the issue of spaces in Volume Names is fixed. Works for me!

Leave a Reply

Your email address will not be published. Required fields are marked *