Skip to content

Instantly share code, notes, and snippets.

@pudquick
Last active April 27, 2022 16:47
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pudquick/f150b59dd68500099a56184dc25f1300 to your computer and use it in GitHub Desktop.
Save pudquick/f150b59dd68500099a56184dc25f1300 to your computer and use it in GitHub Desktop.
List and control Spotlight exclusions in OS X via python and pyobjc on OS X 10.11
# Only tested on OSX 10.11.5
import objc
from Foundation import NSBundle
Metadata_bundle = NSBundle.bundleWithIdentifier_('com.apple.Metadata')
functions = [
('_MDCopyExclusionList', b'@'),
('_MDSetExclusion', b'@@I'),
]
objc.loadBundleFunctions(Metadata_bundle, globals(), functions)
# get the current exclusions (returns list of path strings)
current_exclusions = _MDCopyExclusionList()
# add an exclusion for a path
result = _MDSetExclusion('/Path/We/Want/To/Exclude', 1)
# remove an exclusion for a path
result = _MDSetExclusion('/Path/We/No/Longer/Want/To/Exclude', 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment