#!/bin/sh
CONSOLE_USER_NAME="$(/usr/bin/stat -f "%Su" /dev/console)"
result=$(defaults read /Users/"$CONSOLE_USER_NAME"/Library/Preferences/com.apple.screensaver askForPassword)
echo "<result>$result</result>"
@carlo.anselmi how is this setting being set, a profile?
The reason I asked the above, is that what @bpavlov posted is valid if you've used defaults to set the settings.
However, if using a profile.. defaults will not pick that up.
As an example, the below is the output for me from @bpavlov's script:
<result>0</result>
But if I look at my Mac I can see it enforced:

defaults is not profiles aware, unless it's an MCX set-once profile (afaik - some testing to be done on this).
However, CFPreferences is:
#!/usr/bin/python
import CoreFoundation
domain = 'com.apple.screensaver'
key = 'askForPassword'
key_value = CoreFoundation.CFPreferencesCopyAppValue(key, domain)
print 'Key Value = ', key_value
key_forced = CoreFoundation.CFPreferencesAppValueIsForced(key, domain)
print 'Key Forced = ', key_forced
This then returns:
Key Value = True
Key Forced = True
With the 1st being the value of the key, & the 2nd whether or not it's being enforced via a profile.
Hello and many thanks for your responses...
@bentoms
Screensaver password/idle time are set with a custom profile, as per this article http://www.johnkitzmiller.com/blog/security-privacy-configuration-profile-bug-in-casper-9-82/
It seems that using @bpavlov suggestion reports correctly in JSS inventory but I'll double check on the client side...
Thank you all again!
I would go with the recommendation by @bentoms if you're using a configuration profile.
Does anyone know if this issue has been corrected in Casper 9.91? Or, is there a way to allow users to pick their own settings for the screensaver in the solution from John Kitzmiller?
@macmule interesting my EA returns. I wonder why you get True : True
Key Value = 1
Key Forced = True
<result>1 : True</result>
@jhbush1973 I probably messed about with something. :)
@jhbush1973 Yours is probably set as an INT (or a STRING)
@bentoms Yours is probably a BOOL
Hi there,
I'm trying to update the above to run on Monterey via Python3 but am getting the error:
ModuleNotFoundError: No module named 'CoreFoundation'
I've tried setting the path to the module (which from what I can see is present) and also setting it via find_library but this is not working.
I ideally want this to run without having to install anything else, if possible. If anyone has any suggestions I'd be very grateful.
#!/usr/bin/python3
import os
from ctypes.util import find_library
pathCoreFoundation = "/System/Library/Frameworks/CoreFoundation.framework/Versions/Current/CoreFoundation"
os.path.exists(pathCoreFoundation)
CoreFoundation = find_library(pathCoreFoundation)
print("The library I am importing is:", CoreFoundation)
import CoreFoundation
domain = 'com.apple.screensaver'
key = 'askForPassword'
key_value = CoreFoundation.CFPreferencesCopyAppValue(key, domain)
print ('Key Value = ', key_value)
key_forced = CoreFoundation.CFPreferencesAppValueIsForced(key, domain)
print ('Key Forced = ', key_forced)