def testFunctions(self):
        ref = SCPreferencesCreate(None, "pyobjc.test", "pyobjc.test")
        self.assertIsInstance(ref, SCPreferencesRef)

        r = SCPreferencesAddValue(ref, "use",
                NSMutableDictionary.dictionaryWithDictionary_(
                    { "python2": True, "python3": False }))
        self.assertTrue(r)

        v = SCPreferencesPathCreateUniqueChild(ref, "/")
        self.assertIsInstance(v, unicode)

        v = SCPreferencesPathGetValue(ref, "/use")
        self.assertIsInstance(v, NSDictionary)

        v = SCPreferencesPathSetValue(ref, "/use", dict(python2=True, python3=True))
        self.assertTrue(v is True)

        v = SCPreferencesPathSetLink(ref, "/use_python", "/use")
        self.assertTrue(v is True)

        v = SCPreferencesPathGetLink(ref, "/use_python")
        self.assertEqual(v, "/use")

        v = SCPreferencesPathRemoveValue(ref, "/use")
        self.assertTrue(v is True)
    def testFunctions(self):
        ref = SCPreferencesCreate(None, "pyobjc.test", "pyobjc.test")
        self.assertIsInstance(ref, SCPreferencesRef)

        r = SCPreferencesAddValue(
            ref, "use",
            NSMutableDictionary.dictionaryWithDictionary_({
                "python2": True,
                "python3": False
            }))
        self.assertTrue(r)

        v = SCPreferencesPathCreateUniqueChild(ref, "/")
        self.assertIsInstance(v, unicode)

        v = SCPreferencesPathGetValue(ref, "/use")
        self.assertIsInstance(v, NSDictionary)

        v = SCPreferencesPathSetValue(ref, "/use",
                                      dict(python2=True, python3=True))
        self.assertTrue(v is True)

        v = SCPreferencesPathSetLink(ref, "/use_python", "/use")
        self.assertTrue(v is True)

        v = SCPreferencesPathGetLink(ref, "/use_python")
        self.assertEqual(v, "/use")

        v = SCPreferencesPathRemoveValue(ref, "/use")
        self.assertTrue(v is True)
Exemple #3
0
def fixSpotlight ():
  DISABLED_ITEMS=set(["MENU_WEBSEARCH", "MENU_SPOTLIGHT_SUGGESTIONS", "OTHER", "BOOKMARKS", "MESSAGES"])
  REQUIRED_ITEM_KEYS=set(["enabled", "name"])
  BUNDLE_ID="com.apple.Spotlight"
  PREF_NAME="orderedItems"
  DEFAULT_VALUE=[
    {'enabled' : True, 'name' : 'APPLICATIONS'},
    {'enabled' : False, 'name' : 'MENU_SPOTLIGHT_SUGGESTIONS'},
    {'enabled' : True, 'name' : 'MENU_CONVERSION'},
    {'enabled' : True, 'name' : 'MENU_EXPRESSION'},
    {'enabled' : True, 'name' : 'MENU_DEFINITION'},
    {'enabled' : True, 'name' : 'SYSTEM_PREFS'},
    {'enabled' : True, 'name' : 'DOCUMENTS'},
    {'enabled' : True, 'name' : 'DIRECTORIES'},
    {'enabled' : True, 'name' : 'PRESENTATIONS'},
    {'enabled' : True, 'name' : 'SPREADSHEETS'},
    {'enabled' : True, 'name' : 'PDF'},
    {'enabled' : False, 'name' : 'MESSAGES'},
    {'enabled' : True, 'name' : 'CONTACT'},
    {'enabled' : True, 'name' : 'EVENT_TODO'},
    {'enabled' : True, 'name' : 'IMAGES'},
    {'enabled' : False, 'name' : 'BOOKMARKS'},
    {'enabled' : True, 'name' : 'MUSIC'},
    {'enabled' : True, 'name' : 'MOVIES'},
    {'enabled' : True, 'name' : 'FONTS'},
    {'enabled' : False, 'name' : 'MENU_OTHER'},
    {'enabled' : False, 'name' : 'MENU_WEBSEARCH'}
  ]

  items = CFPreferencesCopyValue(PREF_NAME, BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
  newItems = None
  if items is None or len(items) is 0:
    # Actual preference values are populated on demand; if the user
    # hasn't previously configured Spotlight, the preference value
    # will be unavailable
    newItems = DEFAULT_VALUE
  else:
    newItems = NSMutableArray.new()
    for item in items:
      print item['name']
      missing_keys = []
      for key in REQUIRED_ITEM_KEYS:
        if not item.has_key(key):
          missing_keys.append(key)

      if len(missing_keys) != 0:
        print "Preference item %s is missing expected keys (%s), skipping" % (item, missing_keys)
        newItems.append(item)
        continue

      if item["name"] not in DISABLED_ITEMS:
        newItems.append(item)
        continue

      newItem = NSMutableDictionary.dictionaryWithDictionary_(item)
      newItem.setObject_forKey_(0, "enabled")
      newItems.append(newItem)

  CFPreferencesSetValue(PREF_NAME, newItems, BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
  CFPreferencesSynchronize(BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
Exemple #4
0
 def _setupPaths(self):
     '''
     Read the path setting from ~/.pyupconfig
     '''
     self.settingPath = PreferenceSetting.settingPath()
     settings = PreferenceSetting.load()
     self.data = NSMutableDictionary.dictionaryWithDictionary_(settings)
  def SetProxy(self, enable=True, pac=CORP_PROXY):
    """Set proxy autoconfig."""

    proxies = NSMutableDictionary.dictionaryWithDictionary_(
        self.ReadProxySettings())
    logging.debug('initial proxy settings: %s', proxies)
    proxies['ProxyAutoConfigURLString'] = pac
    if enable:
      proxies['ProxyAutoConfigEnable'] = 1
    else:
      proxies['ProxyAutoConfigEnable'] = 0
    logging.debug('Setting ProxyAutoConfigURLString to %s and '
                  'ProxyAutoConfigEnable to %s', pac, enable)
    result = SCDynamicStoreSetValue(self.store,
                                    'State:/Network/Global/Proxies',
                                    proxies)
    logging.debug('final proxy settings: %s', self.ReadProxySettings())
    return result
Exemple #6
0
  def SetProxy(self, enable=True, pac=CORP_PROXY):
    """Set proxy autoconfig."""

    proxies = NSMutableDictionary.dictionaryWithDictionary_(
        self.ReadProxySettings())
    logging.debug('initial proxy settings: %s', proxies)
    proxies['ProxyAutoConfigURLString'] = pac
    if enable:
      proxies['ProxyAutoConfigEnable'] = 1
    else:
      proxies['ProxyAutoConfigEnable'] = 0
    logging.debug('Setting ProxyAutoConfigURLString to %s and '
                  'ProxyAutoConfigEnable to %s', pac, enable)
    result = SCDynamicStoreSetValue(self.store,
                                    'State:/Network/Global/Proxies',
                                    proxies)
    logging.debug('final proxy settings: %s', self.ReadProxySettings())
    return result
Exemple #7
0
    def saveSettings(self):
        '''
        Save the path setting to setting file
        '''
        jsonData = NSMutableDictionary.dictionaryWithDictionary_(self.data)
        paths = NSMutableArray.array()
        for directory in self.data['paths']:
            paths.addObject_(directory.directoryToDict())

        jsonData['paths'] = paths
        data = NSJSONSerialization.dataWithJSONObject_options_error_(
            jsonData, 0, None)
        if len(data) > 0 and not data[0].writeToFile_atomically_(
                self.settingPath, True):
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                "Error", "Confirm", None, None, "Save setting failed.")
            alert.runModal()
        else:
            # Notify the app to reload settings
            self.callback(*self.args)
Exemple #8
0
# 	"Negative": "NEGA"
# }

# # newParam = GSCustomParameter.alloc().init()

# # font.addCustomParameter_(newParam)
# # font.addCustomParameter_("Axes")
# # add them to the font
# font.setCustomParameter_forKey_(fontAxes, "Axes")

# print(font.customParameterForKey_("Axes"))

from Foundation import NSMutableDictionary, NSMutableArray
fontAxes = NSMutableArray.arrayWithArray_([
    NSMutableDictionary.dictionaryWithDictionary_({
        "Name": "Weight",
        "Tag": "wght"
    }),
    NSMutableDictionary.dictionaryWithDictionary_({
        "Name": "Negative",
        "Tag": "NEGA"
    })
])
font.setCustomParameter_forKey_(fontAxes, "Axes")

# ============================================================================
# remove old masters =========================================================

# just do it twice for now to delete original two – would need more flexibility to be abstracted to other fonts
font.removeFontMasterAtIndex_(0)
font.removeFontMasterAtIndex_(0)
def fixSpotlight():
    DISABLED_ITEMS = set(["MENU_WEBSEARCH", "MENU_SPOTLIGHT_SUGGESTIONS"])
    REQUIRED_ITEM_KEYS = set(["enabled", "name"])
    BUNDLE_ID = "com.apple.Spotlight"
    PREF_NAME = "orderedItems"
    DEFAULT_VALUE = [{
        'enabled': True,
        'name': 'APPLICATIONS'
    }, {
        'enabled': False,
        'name': 'MENU_SPOTLIGHT_SUGGESTIONS'
    }, {
        'enabled': True,
        'name': 'MENU_CONVERSION'
    }, {
        'enabled': True,
        'name': 'MENU_EXPRESSION'
    }, {
        'enabled': True,
        'name': 'MENU_DEFINITION'
    }, {
        'enabled': True,
        'name': 'SYSTEM_PREFS'
    }, {
        'enabled': True,
        'name': 'DOCUMENTS'
    }, {
        'enabled': True,
        'name': 'DIRECTORIES'
    }, {
        'enabled': True,
        'name': 'PRESENTATIONS'
    }, {
        'enabled': True,
        'name': 'SPREADSHEETS'
    }, {
        'enabled': True,
        'name': 'PDF'
    }, {
        'enabled': True,
        'name': 'MESSAGES'
    }, {
        'enabled': True,
        'name': 'CONTACT'
    }, {
        'enabled': True,
        'name': 'EVENT_TODO'
    }, {
        'enabled': True,
        'name': 'IMAGES'
    }, {
        'enabled': True,
        'name': 'BOOKMARKS'
    }, {
        'enabled': True,
        'name': 'MUSIC'
    }, {
        'enabled': True,
        'name': 'MOVIES'
    }, {
        'enabled': True,
        'name': 'FONTS'
    }, {
        'enabled': True,
        'name': 'MENU_OTHER'
    }, {
        'enabled': False,
        'name': 'MENU_WEBSEARCH'
    }]

    items = CFPreferencesCopyValue(PREF_NAME, BUNDLE_ID,
                                   kCFPreferencesCurrentUser,
                                   kCFPreferencesAnyHost)
    newItems = None
    if items is None or len(items) is 0:
        # Actual preference values are populated on demand; if the user
        # hasn't previously configured Spotlight, the preference value
        # will be unavailable
        newItems = DEFAULT_VALUE
    else:
        newItems = NSMutableArray.new()
        for item in items:
            missing_keys = []
            for key in REQUIRED_ITEM_KEYS:
                if not item.has_key(key):
                    missing_keys.append(key)

            if len(missing_keys) != 0:
                print "Preference item %s is missing expected keys (%s), skipping" % (
                    item, missing_keys)
                newItems.append(item)
                continue

            if item["name"] not in DISABLED_ITEMS:
                newItems.append(item)
                continue

            newItem = NSMutableDictionary.dictionaryWithDictionary_(item)
            newItem.setObject_forKey_(0, "enabled")
            newItems.append(newItem)

    CFPreferencesSetValue(PREF_NAME, newItems, BUNDLE_ID,
                          kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
    CFPreferencesSynchronize(BUNDLE_ID, kCFPreferencesCurrentUser,
                             kCFPreferencesAnyHost)
Exemple #10
0
ls_prefs = os.path.join(
    NSHomeDirectory(),
    u'Library/Preferences/com.apple.LaunchServices/com.apple.LaunchServices')
ls_prefs_plist = ls_prefs + u'.plist'

if os.path.isfile(ls_prefs_plist):
    # read it in
    current_prefs = CFPreferencesCopyMultiple(None, ls_prefs,
                                              kCFPreferencesAnyUser,
                                              kCFPreferencesCurrentHost)
else:
    # make a new dictionary
    current_prefs = NSMutableDictionary()

# Get any existing key or a new blank dict if not present
magnified = current_prefs.get(u'LSHighResolutionModeIsMagnified',
                              NSMutableDictionary())
magnified_editable = NSMutableDictionary.dictionaryWithDictionary_(magnified)
# Build our values
options = NSMutableArray.alloc().init()
options.append(bookmark)
# A value of 3 = enabled, value of 2 = disabled
options.append(3)
magnified_editable[lowres_app_id] = options

# Update the setting
update_dict = NSMutableDictionary()
update_dict[u'LSHighResolutionModeIsMagnified'] = magnified_editable
result = CFPreferencesSetMultiple(update_dict, None, ls_prefs,
                                  kCFPreferencesAnyUser,
                                  kCFPreferencesCurrentHost)