If you specify -currentHost
then the information returned by defaults
is restricted to preferences operations to the host the user is currently logged in on (these host preferences can be found in ~/Library/Preferences/ByHost
).
• Operations on the defaults database normally apply to any host the user may log in on, but may be restricted to apply only to a specific
host.
• If no host is provided, preferences operations will apply to any host the user may log in on.
-currentHost
Restricts preferences operations to the host the user is currently logged in on.
-host hostname
Restricts preferences operations to hostname.
So in order to get the information you've asked about:
$ defaults read com.apple.screensaver
By omitting the -currentHost
option it should return:
{
askForPassword = 1;
askForPasswordDelay = 0;
}
If you wanted to use CFPrefs
:
#import <CoreFoundation/CoreFoundation.h>
#define EX_KEY "askForPasswordDelay"
#define EX_ID "com.apple.screensaver"
extern CFDictionaryRef _CFPreferencesCopyApplicationMap(CFStringRef userName, CFStringRef hostName);
int main(int argc, char *argv[])
{
@autoreleasepool
{
CFURLRef current_url;
CFStringRef path;
CFMutableStringRef plist_path;
CFPropertyListRef value;
CFDictionaryRef app_map = _CFPreferencesCopyApplicationMap(
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
CFArrayRef urls = CFDictionaryGetValue(app_map, CFSTR(EX_ID));
current_url = CFArrayGetValueAtIndex(urls, 0);
path = CFURLCopyPath(current_url);
plist_path = CFStringCreateMutable(kCFAllocatorDefault, 0);
CFStringAppend(plist_path, path);
CFStringAppend(plist_path, CFSTR(EX_ID));
CFPropertyListRef prefs = CFPreferencesCopyValue(
CFSTR(EX_KEY),
CFSTR(EX_ID),
CFSTR("kCFPreferencesCurrentUser"),
CFSTR("kCFPreferencesAnyHost"));
printf("CFPreferencesCopyValue \"%s\" of %s via ApplicationMap at path:\n", EX_KEY, EX_ID);
CFShow(plist_path);
CFShow(prefs);
CFRelease(prefs);
CFRelease(plist_path);
CFRelease(path);
CFRelease(app_map);
}
}
Output:
CFPreferencesCopyValue "askForPasswordDelay" of com.apple.screensaver via ApplicationMap at path:
/Users/Username/Library/Preferences/com.apple.screensaver
<CFNumber 0x47 [0x7fffbf0a9d80]>{value = +0.0, type = kCFNumberFloat32Type}
↳ OSX Man Pages : defaults