Last active
May 18, 2021 01:34
-
-
Save pudquick/ac8f22326f095ed2690e to your computer and use it in GitHub Desktop.
Loading framework variables (aka constants) from pyObjC for arbitrary frameworks
This file contains 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
from Foundation import NSBundle | |
# Load the framework bundle by its identifier | |
Metadata_bundle = NSBundle.bundleWithIdentifier_("com.apple.Metadata") | |
# Can also use: bundleWithPath or bundleWithURL | |
# Load the variable aka constant from the framework into globals | |
# This says to load whatever "kMDSPreferencesName" is and the type should be "an NSObject" aka "figure it out" | |
# which ends up giving us a NSString which pyObjC bridges to a python string nicely | |
objc.loadBundleVariables(Metadata_bundle, globals(), [('kMDSPreferencesName', '@')]) | |
# >>> kMDSPreferencesName | |
# u'com.apple.SpotlightServer' | |
# OMG wasn't that soooo much easier than using ctypes? | |
# https://gist.github.com/pudquick/8f65bb9b306f91eafdcc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment