Last active
November 24, 2016 14:49
-
-
Save matheusfaustino/af6ea3d0af3d220657596b3fc8f2dc8d to your computer and use it in GitHub Desktop.
function that put OSX to sleep after some seconds/minutes/hours. I use it when I am listening music at night
This file contains hidden or 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
sleep_after() { | |
local sleep_time=$1; | |
if [[ $2 = "hour" ]] then | |
sleep_time=$(($sleep_time*60*60)); | |
elif [[ $2 = "min" ]] then | |
sleep_time=$(($sleep_time*60)); | |
elif [[ !$2 ]] then | |
echo "options is not valid: $2"; | |
return 0; | |
fi | |
sleep $sleep_time; | |
osascript -e 'tell application "Finder" to sleep'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use it like this:
sleep_after <number> <hour/min>(optional)
sleep_after 10 # it will be in seconds
sleep_after 10 min
sleep_after 1 hour