Skip to content

Instantly share code, notes, and snippets.

@daxeh
Created July 21, 2017 15:21
Show Gist options
  • Save daxeh/8945f55b8cf94d23a5f7bb2beeda81bd to your computer and use it in GitHub Desktop.
Save daxeh/8945f55b8cf94d23a5f7bb2beeda81bd to your computer and use it in GitHub Desktop.
OSX Automator Applescript prevent computer from sleeping. Simplified interaction with auto-dismiss prompt and notification
on run {input, parameters}
set clickedValue to "Continue"
repeat while clickedValue is not "Don't Continue"
display notification "Executing command 'caffeinate -t 9600' " with title "Awake Notification" subtitle "Caffeinate started."
if (do shell script "caffeinate -t 9600") is "" then
set theDialogText to "Awake duration ended. Would you like to continue?"
set theDialog to display dialog theDialogText giving up after 5 buttons {"Don't Continue", "Continue"} default button "Continue"
set clickedValue to button returned of theDialog
end if
end repeat
display notification with title "Awake Notification" subtitle "Caffeinate ended." sound name "Frog"
return input
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment