Skip to content

Instantly share code, notes, and snippets.

@opragel
Forked from pudquick/fastuser_logincheck.py
Last active April 26, 2016 17:47
Show Gist options
  • Save opragel/f39fbf8594f16f55896e2d57f87cf9ed to your computer and use it in GitHub Desktop.
Save opragel/f39fbf8594f16f55896e2d57f87cf9ed to your computer and use it in GitHub Desktop.
Using CGSSessionCopyAllSessionProperties to detect logged-in users the way the Fast User switching menu extra does on OS X with python and pyobjc
import objc
from Foundation import NSBundle
CG_bundle = NSBundle.bundleWithIdentifier_('com.apple.CoreGraphics')
functions = [("CGSSessionCopyAllSessionProperties", b"@"),]
objc.loadBundleFunctions(CG_bundle, globals(), functions)
allSessionProperties = CGSSessionCopyAllSessionProperties()
for session in allSessionProperties:
print session['kCGSSessionUserNameKey']
print session['kCGSessionLoginDoneKey']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment