Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created June 15, 2016 17:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pudquick/097f97f4cb67c554f04dba6b5a09a506 to your computer and use it in GitHub Desktop.
Save pudquick/097f97f4cb67c554f04dba6b5a09a506 to your computer and use it in GitHub Desktop.
Locking the screen immediately with pyobjc
import objc
from Foundation import NSBundle
login_bundle = NSBundle.bundleWithPath_('/System/Library/PrivateFrameworks/login.framework')
functions = [('SACLockScreenImmediate', '@'),]
objc.loadBundleFunctions(login_bundle, globals(), functions)
# Lock the screen regardless of security settings or who is logged in
result = SACLockScreenImmediate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment