Skip to content

Instantly share code, notes, and snippets.

@matheusfaustino
Last active November 24, 2016 14:49
Show Gist options
  • Save matheusfaustino/af6ea3d0af3d220657596b3fc8f2dc8d to your computer and use it in GitHub Desktop.
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
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';
}
@matheusfaustino
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment