Skip to content

Instantly share code, notes, and snippets.

Created August 22, 2011 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1161928 to your computer and use it in GitHub Desktop.
Save anonymous/1161928 to your computer and use it in GitHub Desktop.
AppleScript to mount an external disk and execute an app.
(*
Mount external disk, if not, ask user to connect it.
When disk is mounted, execute Automator Workflow.
*)
property extDisk : "Backup" -- name of the external hard disk or volume
property automatorWorkflowApp : "/Path/To/AutomatorWorkflow.app" -- the app to run
if mountDisk(extDisk) then
run application automatorWorkflowApp
else
display dialog ("Could not find disk \"" & extDisk & "\"") with icon stop
end if
-- check if disk is mounted, otherwise try to mount it
to mountDisk(diskName)
tell application "System Events"
repeat while not (disk diskName exists)
try -- to mount it
do shell script "diskutil mount " & last word of ¬
(do shell script "diskutil list | grep " & quoted form of diskName)
on error
try
display dialog "Please connect the disk \"" & diskName & ¬
"\" to your computer." buttons {"Cancel", "Try again"} ¬
default button 2 cancel button 1 with title "Cannot find disk" with icon caution
on error -128 --user cancelled
return false
end try
end try
delay 3 -- wait 3 seconds for Finder to mount the disk
end repeat
end tell
return true
end mountDisk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment