Last active
April 27, 2022 16:47
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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