Skip to content

Instantly share code, notes, and snippets.

@yspreen
Last active February 16, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yspreen/3101fd3f849950b3224a346893025b56 to your computer and use it in GitHub Desktop.
Save yspreen/3101fd3f849950b3224a346893025b56 to your computer and use it in GitHub Desktop.
Automatically keep your MacBook from sleeping, when an eGPU is connected
#!/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