Skip to content

Instantly share code, notes, and snippets.

@matthacksteiner
Last active December 16, 2015 15:59
Show Gist options
  • Save matthacksteiner/5459821 to your computer and use it in GitHub Desktop.
Save matthacksteiner/5459821 to your computer and use it in GitHub Desktop.
Go to sleep #applescript
set sleepTime to 0
set theText to text returned of (display dialog "Ruhezustand aktivieren in:" default answer "1 h 30 m")
set defaults to AppleScript's text item delimiters
set AppleScript's text item delimiters to " " -- use " " as delimiters
set theWords to text items of theText
set timesToRun to (number of theWords) / 2
set n to 0 -- index
-- parse time.
repeat timesToRun times
set n to n + 1
set tempTime to item n of theWords as integer
set n to n + 1
set tempWord to item n of theWords
if tempWord contains "h" then -- hours
set sleepTime to sleepTime + tempTime * 3600
else if tempWord contains "m" then -- minutes
set sleepTime to sleepTime + tempTime * 60
else -- seconds
set sleepTime to sleepTime + tempTime
end if
end repeat
set AppleScript's text item delimiters to defaults -- restore default delimiters
delay sleepTime
tell application "System Events"
sleep
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment