Exemplo n.º 1
0
    def save(self):
        '''saves our (modified) Dock preferences'''
        # unload Dock launchd job so we can make our changes unmolested
        subprocess.call(
            ['/bin/launchctl', 'unload', self._DOCK_LAUNCHAGENT_FILE])

        for key in self._SECTIONS:
            try:
                CFPreferencesSetAppValue(key, self.items[key], self._DOMAIN)
            except Exception:
                raise DockError
        for key in self._MUTABLE_KEYS:
            if getattr(self, key):
                try:
                    CFPreferencesSetAppValue(key.replace('_', '-'),
                                             getattr(self, key), self._DOMAIN)
                except Exception:
                    raise DockError
        if not CFPreferencesAppSynchronize(self._DOMAIN):
            raise DockError

        # restart the Dock
        subprocess.call(
            ['/bin/launchctl', 'load', self._DOCK_LAUNCHAGENT_FILE])
        subprocess.call(['/bin/launchctl', 'start', self._DOCK_LAUNCHAGENT_ID])
Exemplo n.º 2
0
    def save(self):
        """Saves our (modified) Dock preferences."""
        # unload Dock launchd job so we can make our changes unmolested
        subprocess.call(["/bin/launchctl", "unload", self._DOCK_LAUNCHAGENT_FILE])

        for key in self._SECTIONS:
            try:
                CFPreferencesSetAppValue(key, self.items[key], self._DOMAIN)
            except Exception:
                raise DockError
        for key in self._MUTABLE_KEYS:
            if getattr(self, key.replace("-", "_")) is not None:
                try:
                    CFPreferencesSetAppValue(
                        key.replace("_", "-"),
                        getattr(self, key.replace("-", "_")),
                        self._DOMAIN,
                    )
                except Exception:
                    raise DockError
        if not CFPreferencesAppSynchronize(self._DOMAIN):
            raise DockError

        # restart the Dock
        subprocess.call(["/bin/launchctl", "load", self._DOCK_LAUNCHAGENT_FILE])
        subprocess.call(["/bin/launchctl", "start", self._DOCK_LAUNCHAGENT_ID])
Exemplo n.º 3
0
def set_pref(pref_name, pref_value):
    """
    Sets a preference
    """
    # pylint: disable=E0602
    CFPreferencesSetAppValue(pref_name, pref_value, BUNDLE_ID)
    CFPreferencesAppSynchronize(BUNDLE_ID)
def set_selfcontrol_setting(key, value, username):
    """ sets a single default setting of SelfControl for the provied username """
    NSUserDefaults.resetStandardUserDefaults()
    originalUID = os.geteuid()
    os.seteuid(getpwnam(username).pw_uid)
    CFPreferencesSetAppValue(key, value, "org.eyebeam.SelfControl")
    CFPreferencesAppSynchronize("org.eyebeam.SelfControl")
    NSUserDefaults.resetStandardUserDefaults()
    os.seteuid(originalUID)
Exemplo n.º 5
0
def write_pref(key, value):
    # NSLog('Setting "{0}" to "{1}"'.format(key, value))
    CFPreferencesSetAppValue(key, value, kCFPreferencesCurrentApplication)
    if not CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication):
        d = PyDialog.AlertDialog(
            'Something went wrong...',
            'Unable to save preference: "{0}"'.format(key))
        d.display()
        NSLog('ERROR: unable to save user preferences!')
Exemplo n.º 6
0
def add_receipt(yo_args):
    """Add a receipt to current user's receipt preferences.

    Args:
        yo_args (list of str): Arguments to yo app as for a subprocess.
    """
    receipts = get_receipts()
    receipts[repr(yo_args)] = NSDate.alloc().init()
    CFPreferencesSetAppValue("DeliveryReceipts", receipts, BUNDLE_ID)
    CFPreferencesAppSynchronize(BUNDLE_ID)
Exemplo n.º 7
0
def configure(prompt_list):
    """Gets configuration options and saves them to preferences store"""
    darwin_vers = int(os.uname()[2].split('.')[0])
    edited_prefs = {}
    for (key, prompt) in prompt_list:
        newvalue = raw_input_with_default('%15s: ' % prompt, pref(key))
        if darwin_vers == 10:
            # old behavior in SL: hitting return gives you an empty string,
            # and means accept the default value.
            edited_prefs[key] = newvalue or pref(key) or ''
        else:
            # just use the edited value as-is
            edited_prefs[key] = newvalue

    if FOUNDATION_SUPPORT:
        for key, value in edited_prefs.items():
            try:
                CFPreferencesSetAppValue(key, value, BUNDLE_ID)
            except BaseException:
                print >> sys.stderr, 'Could not save configuration!'
                raise ConfigurationSaveError
            # remove repo_path if it exists since we don't use that
            # any longer (except for backwards compatibility) and we don't
            # want it getting out of sync with the repo_url
            CFPreferencesSetAppValue('repo_path', None, BUNDLE_ID)
        CFPreferencesAppSynchronize(BUNDLE_ID)

    else:
        try:
            existing_prefs = plistlib.readPlist(PREFSPATH)
            existing_prefs.update(edited_prefs)
            # remove repo_path if it exists since we don't use that
            # any longer (except for backwards compatibility) and we don't
            # want it getting out of sync with the repo_url
            if 'repo_path' in existing_prefs:
                del existing_prefs['repo_path']
            plistlib.writePlist(existing_prefs, PREFSPATH)
        except (IOError, OSError, ExpatError):
            print >> sys.stderr, ('Could not save configuration to %s' %
                                  PREFSPATH)
            raise ConfigurationSaveError
Exemplo n.º 8
0
def modify_ncprefs_plist(key, value, item_index):
    # make an immutuble copy of the 'apps' array in ncprefs
    new_apps_array = NSMutableArray.alloc().initWithArray_(pl)
    # make a mutable copy of the target dict within the array
    new_dict = NSMutableDictionary.alloc().initWithDictionary_copyItems_(
        new_apps_array[item_index], True)
    # set the value
    new_dict[key] = value
    # replace the mutible dict within the mutable array
    new_apps_array.replaceObjectAtIndex_withObject_(item_index, new_dict)
    # replace the array in the ncprefs plist
    CFPreferencesSetAppValue("apps", new_apps_array, NCPREFS_PLIST)
Exemplo n.º 9
0
    def save(self):
        """saves our (modified) TouchBar preferences"""

        for key in self._SECTIONS:
            try:
                CFPreferencesSetAppValue(key, self.items[key], self._DOMAIN)
            except Exception:
                raise TouchBarError
        if not CFPreferencesAppSynchronize(self._DOMAIN):
            raise TouchBarError

        # restart the TouchBar
        subprocess.call(["/usr/bin/killall", "ControlStrip"])
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
 def check_and_disable_appnap_for_pdapp(self):
     """Log a warning if AppNap isn't disabled on the system."""
     appnap_disabled = CFPreferencesCopyAppValue('NSAppSleepDisabled',
                                                 'com.adobe.PDApp')
     if not appnap_disabled:
         self.output("WARNING: A bug in Creative Cloud Packager makes "
                     "it likely to stall indefinitely whenever the app "
                     "window is hidden or obscured due to App Nap. To "
                     "prevent this, we're setting a user preference to "
                     "disable App Nap for just the "
                     "Adobe PDApp application. This can be undone using "
                     "this command: 'defaults delete com.adobe.PDApp "
                     "NSAppSleepDisabled")
         CFPreferencesSetAppValue('NSAppSleepDisabled', True,
                                  'com.adobe.PDApp')
Exemplo n.º 12
0
    if args.set_notification_grouping:
        item_found, item_index, _, _, _ = bundle_id_exists(
            args.set_notification_grouping[1])
        if item_found:
            set_notification_grouping(args.set_notification_grouping[0])

    if args.get_global_show_previews:
        value = CFPreferencesCopyAppValue('content_visibility', NCPREFS_PLIST)
        print(get_show_previews(value))

    if args.set_global_show_previews:
        option = args.set_global_show_previews[0]
        if option == "always":
            new_option = 3
        elif option == "unlocked":
            new_option = 2
        elif option == "never":
            new_option = 1
        else:
            error(
                f"{option} unrecognized, must be one of 'always', 'unlocked' or 'never'"
            )
            sys.exit(1)

        CFPreferencesSetAppValue('content_visibility', new_option,
                                 NCPREFS_PLIST)
        kill_usernoted()

    if args.version:
        print(f"{NCPREFSPY_VERSION}")
Exemplo n.º 13
0
#!/usr/bin/python

import os
from Foundation import CFPreferencesCopyAppValue, \
                       CFPreferencesSetAppValue

storefront_canada = "143455-6,13"
apple_id = os.environ['APPLE_USERNAME']
account_info = {
    'bagtype': 1,
    'credit': "",
    'dsid': 10231587043,
    'identifier': apple_id,
    'kind': 0,
    'signedin': False,
    'storefront': storefront_canada,
}

known_accounts = [account_info]
CFPreferencesSetAppValue('KnownAccounts', known_accounts, 'com.apple.commerce')

# We may not need to set this, and we'd probably need to create proper nested NSDictionaries first
# primary_account = {
#     0: {
#         1: account_info,
#     }
# }
#CFPreferencesSetAppValue('PrimaryAccount', primary_account, 'com.apple.commerce')

CFPreferencesSetAppValue('Storefront', storefront_canada, 'com.apple.appstore')
Exemplo n.º 14
0
#!/usr/bin/python

from Foundation import CFPreferencesSetAppValue, \
                       CFPreferencesAppSynchronize

app_id = "com.apple.screenSaver"
CFPreferencesSetAppValue("idleTime", 600, app_id)
CFPreferencesAppSynchronize(app_id)