Created
August 22, 2011 08:26
-
-
Save anonymous/1161928 to your computer and use it in GitHub Desktop.
AppleScript to mount an external disk and execute an app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
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