Last active
February 16, 2019 16:45
-
-
Save yspreen/3101fd3f849950b3224a346893025b56 to your computer and use it in GitHub Desktop.
Automatically keep your MacBook from sleeping, when an eGPU is connected
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
#!/bin/bash | |
function no_sleep { | |
if ! [ -n "${last_pid+x}" ]; then | |
caffeinate -d & | |
last_pid=$! && | |
echo start caffeinate | |
fi | |
sleep 60 | |
} | |
function do_sleep { | |
[ -n "${last_pid+x}" ] && kill -KILL $last_pid && echo stop caffeinate | |
unset last_pid | |
sleep 60 | |
} | |
while true; do | |
system_profiler SPDisplaysDataType | grep -i 'Type: External GPU' >/dev/null && no_sleep || do_sleep | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment