Last active
December 16, 2015 15:59
-
-
Save matthacksteiner/5459821 to your computer and use it in GitHub Desktop.
Go to sleep #applescript
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
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