Last active
March 19, 2021 12:59
-
-
Save deven96/7b01c114d656c56a6a3177c92de493db to your computer and use it in GitHub Desktop.
Checking screen is active on Mac
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/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