Skip to content

Instantly share code, notes, and snippets.

@nikolay-n
Last active November 7, 2020 14:30
Show Gist options
  • Save nikolay-n/2d89c773c5a2913e9392cf64117e3a1a to your computer and use it in GitHub Desktop.
Save nikolay-n/2d89c773c5a2913e9392cf64117e3a1a to your computer and use it in GitHub Desktop.
Checks lock screen status
from Foundation import NSBundle
import objc
BIT_WIDTH = 32
INT_MAX = 2**(BIT_WIDTH-1)-1
MobileKeyBag = NSBundle.bundleWithPath_('/System/Library/PrivateFrameworks/MobileKeyBag.framework')
objc.loadBundleFunctions(MobileKeyBag, globals(), [('MKBDeviceGetGracePeriod', '@@')])
grace = MKBDeviceGetGracePeriod({});
try:
p = grace["GracePeriod"]
if p == INT_MAX:
print("Screen lock disabled")
else:
print "Screen lock {}".format("is not set" if p == -1 else "is set, grace period {}".format(p))
except:
print("Something wrong!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment