def __iter__(self): """Iterator for keys in the specific 'level' of preferences; this will fail to iterate all available keys for the preferences domain since OS X reads from multiple 'levels' and composites them.""" keys = CFPreferencesCopyKeyList(self.bundle_id, self.user, kCFPreferencesCurrentHost) if keys is not None: for i in keys: yield i
def save_user_defaults(prefs): """Write the user preferences for Recipe Robot back to disk. Args: prefs (dict): The dictionary containing a key/value pair for Recipe Robot preferences. """ # Clean up non Recipe Robot related keys that were accidentally collected from the # global preferences by prior versions of Recipe Robot. cfprefs_keylist = CFPreferencesCopyKeyList( BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost ) if cfprefs_keylist: external_keys = [x for x in cfprefs_keylist if x not in PREFERENCE_KEYS] for ext_key in external_keys: CFPreferencesSetAppValue(ext_key, None, BUNDLE_ID) # Save latest values for all Recipe Robot keys. for key in PREFERENCE_KEYS: if prefs.get(key): CFPreferencesSetAppValue(key, prefs[key], BUNDLE_ID) CFPreferencesAppSynchronize(BUNDLE_ID)
def getDefaultsData(app_id, current_host, any_user): '''Returns the content of the defaults domain as an array or dict obejct.''' if app_id == "NSGlobalDomain": app_id = kCFPreferencesAnyApplication if current_host: host_domain = kCFPreferencesCurrentHost else: host_domain = kCFPreferencesAnyHost if any_user: user_domain = kCFPreferencesAnyUser else: user_domain = kCFPreferencesCurrentUser allKeys = CFPreferencesCopyKeyList(app_id, user_domain, host_domain) prefs_dict = CFPreferencesCopyMultiple(allKeys, app_id, user_domain, host_domain) if len(prefs_dict) == 0: errorAndExit("Error: no values found for app id: %s" % app_id) return prefs_dict
def prefs(app_id, user_dom, host_dom): domain_keys = CFPreferencesCopyKeyList(app_id, user_dom, host_dom) domain_dict = CFPreferencesCopyMultiple(domain_keys, app_id, user_dom, host_dom) return domain_dict
def get_keys(): """Returns a list of the names of the keys in Defaults""" return CFPreferencesCopyKeyList(kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
def __iter__(self): keys = CFPreferencesCopyKeyList(self.bundle_id, self.user, kCFPreferencesCurrentHost) if keys is not None: for i in keys: yield i