-
-
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
This file contains hidden or 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
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