Shortcut to eject all external hard drives but not MobileBackups

applescriptbackupejectexternal-diskkeyboard

So far I've been using the following AppleScript to eject all external drives at once conveniently using a shortcut:

tell application "Finder"
    eject (every disk)
end tell

This script is is stored in /Library/Scripts and I have assigned a shortcut to trigger it in FastScripts.

But there's one problem. When you have Time Machine Backups enabled, OS X mounts a virtual MobileBackups volume in /Volumes to store local snapshots. This volume will be ejected alongside all the physical external volumes. I want to avoid this as this will stop local snapshots from being made (until it's mounted again at next login).

How can I add an exception to exclude /Volumes/MobileBackups in the AppleScript above?

Best Answer

This AppleScript code:

tell application "Finder"
    set diskList to the disks
    repeat with mountedDisk in diskList
        if name of mountedDisk is not "MobileBackups" then
            eject mountedDisk
        end if
    end repeat
end tell

ejects all mounted disks except when named MobileBackups, that is, /Volumes/MobileBackups.