Last active
February 9, 2022 08:17
-
-
Save tossmilestone/fe06218d34e9e00eda6ff2a14b297084 to your computer and use it in GitHub Desktop.
Prevent macos to sleep if specified program is running
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
#!/bin/sh | |
if [[ -n "$1" ]]; then | |
pid=$(ps rax | awk '{print $1, $5}' | grep -i "$1" | cut -d ' ' -f 1) | |
if [[ -n $pid ]]; then | |
caffeinate -s -w "$pid" & | |
echo "Systemp sleep prevented by $1" | |
else | |
echo "Sorry, the $1 could not be found." | |
fi | |
else | |
echo "Please enter the name of the program that you want to wait." | |
echo "Example:" | |
echo " prevent_sleep wget" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
pmset -g
to verify if the script is working:the line
sleep 1 (sleep prevented by caffeinate)
should havecaffeinate
.