Skip to content

Instantly share code, notes, and snippets.

@deven96
Last active March 19, 2021 12:59
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 deven96/7b01c114d656c56a6a3177c92de493db to your computer and use it in GitHub Desktop.
Save deven96/7b01c114d656c56a6a3177c92de493db to your computer and use it in GitHub Desktop.
Checking screen is active on Mac
#!/bin/bash
# $screenActive=1 means the screen is active and O is inactive
# View the explanation of the CGSession dictionary at
# https://stackoverflow.com/questions/11505255/osx-check-if-the-screen-is-locked
function checkScreenActiveMac {
python -c 'import sys,Quartz;\
d=Quartz.CGSessionCopyCurrentDictionary();\
sys.exit(d and \
d.get("CGSSessionScreenIsLocked", 0) == 0 and \
d.get("kCGSSessionOnConsoleKey", 0) == 1)'
screenActive=$?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment