Skip to content

Instantly share code, notes, and snippets.

@nriley
Created March 5, 2012 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nriley/1981998 to your computer and use it in GitHub Desktop.
Save nriley/1981998 to your computer and use it in GitHub Desktop.
Multiple disk unmounting script with Time Machine to disk image/iTunes support
property _timeMachineDiskName : "Backup of Babs"
property _diskNamesToTryToEject : {"MaryMedia", "MaryBackup+", "ShirleyClone", "ShirleyLion", "bzzt"}
property _growlApplication : "Go home"
property _growlNotification : "Status"
on _notify(_title, _description)
tell application "GrowlHelperApp" to notify with name _growlNotification title _title description _description application name _growlApplication identifier _growlNotification
end _notify
on run
local _disksToEject, _diskNamesToEject
tell application "GrowlHelperApp" to register as application _growlApplication all notifications {_growlNotification} default notifications {_growlNotification} icon of application "Finder.app"
repeat
try -- wait for Time Machine volume to be unmounted
do shell script "/usr/sbin/diskutil list " & quoted form of _timeMachineDiskName
on error
exit repeat
end try
_notify("Waiting for Time Machine…", _timeMachineDiskName)
delay 1
end repeat
-- quit iTunes (which may be using MaryMedia)
tell application "System Events"
if (bundle identifier of every process contains "com.apple.iTunes") then
tell application "iTunes" to quit
end if
end tell
set _disksToEject to {}
set _diskNamesToEject to {}
tell application "Finder"
set _allDisks to every disk's name
repeat with _diskName in _diskNamesToTryToEject
if _allDisks contains _diskName then
set _diskNamesToEject to _diskNamesToEject & {_diskName as text}
set _disksToEject to _disksToEject & {disk _diskName}
end if
end repeat
set AppleScript's text item delimiters to ", "
my _notify("Ejecting disks…", _diskNamesToEject as text)
eject _disksToEject
end tell
_notify("Disks ejected.", "Go home!")
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment