Skip to content

Instantly share code, notes, and snippets.

Last active May 18, 2021 01:34
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Loading framework variables (aka constants) from pyObjC for arbitrary frameworks
from Foundation import NSBundle
# Load the framework bundle by its identifier
Metadata_bundle = NSBundle.bundleWithIdentifier_("")
# 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''
# OMG wasn't that soooo much easier than using ctypes?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment