Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #this part imports all the required libraries for accessing the preference bundles in os x
- from Foundation import NSMutableArray, NSMutableDictionary
- from Foundation import CFPreferencesSynchronize, CFPreferencesCopyValue, CFPreferencesCopyKeyList, CFPreferencesSetValue, CFPreferencesCopyMultiple, CFPreferencesSetMultiple, kCFPreferencesCurrentUser, kCFPreferencesAnyHost
- import os, sys
- # We only handle Yosemite's spotlight for now
- #this part checks to make sure that u are running the right os x
- majorRelease = int(os.uname()[2].split(".")[0])
- if majorRelease < 14:
- print "Good news! This version of Mac OS X's Spotlight is not known to invade your privacy."
- sys.exit(0)
- #this part is just a big list of things to write to the preference bundle, in our case we're turning off bing & suggestions
- 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'}
- ]
- #this part begins the writing preference bundle proccess, we pass in the items from the list before and all the other junk we brought in
- 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:
- #this part handles errors if things havent been set up yet
- 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)
- #more error hadnling
- if len(missing_keys) is not 0:
- print "Preference item %s is missing expected keys (%s), skipping" % (item, missing_keys)
- newItems.append(item)
- continue
- #little bit more
- if not item["name"] in DISABLED_ITEMS:
- newItems.append(item)
- continue
- #and here we go with some of the writing
- newItem = NSMutableDictionary.dictionaryWithDictionary_(item)
- newItem.setObject_forKey_(0, "enabled")
- newItems.append(newItem)
- #blah mor writing "set value" with all our things from the previous
- CFPreferencesSetValue(PREF_NAME, newItems, BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
- CFPreferencesSynchronize(BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
- #run teh whole program with the classic ()
- fixSpotlight()
- #tell the user it ran
- print "All done. Make sure to log out (and back in) for the changes to take effect."
- ##there u go alexis i broke down the python script :P
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement