Skip to content

Instantly share code, notes, and snippets.

@antlauzon
Last active May 12, 2021 21:53
Show Gist options
  • Save antlauzon/a846aab85269e3edbc399c8903219df6 to your computer and use it in GitHub Desktop.
Save antlauzon/a846aab85269e3edbc399c8903219df6 to your computer and use it in GitHub Desktop.
islocked
#!/usr/bin/env python3
import sys
import os
import sys
import Quartz
d = Quartz.CGSessionCopyCurrentDictionary()
LOCKED_FILE = '$HOME/tmp/.locked'
if d.get('CGSSessionScreenIsLocked') in ['1', 1]:
with open(LOCKED_FILE, 'w') as f:
f.write(int(time.time()))
sys.exit(0)
try:
os.remove(LOCKED_FILE)
except:
pass
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment