Skip to content

Instantly share code, notes, and snippets.

@robperc
Last active March 8, 2016 22:58
Show Gist options
  • Save robperc/f386e73a9448f1728805 to your computer and use it in GitHub Desktop.
Save robperc/f386e73a9448f1728805 to your computer and use it in GitHub Desktop.
PyObjC SharedFileList 10.11.x Fix
"""
LSSharedFileList functions are missing from LaunchServices framework in OS X 10.11.x
(see https://bitbucket.org/ronaldoussoren/pyobjc/issues/126/sharedfilelist-imports-from-pyobjc)
This solution allows for importing of SharedFileList functions without requiring patching of PyObjC
"""
import objc
from Foundation import NSBundle
SFL_bundle = NSBundle.bundleWithIdentifier_('com.apple.coreservices.SharedFileList')
functions = [('LSSharedFileListCreate', '^{OpaqueLSSharedFileListRef=}^{__CFAllocator=}^{__CFString=}@'),
('LSSharedFileListCopySnapshot', '^{__CFArray=}^{OpaqueLSSharedFileListRef=}o^I'),
('LSSharedFileListItemCopyDisplayName', '^{__CFString=}^{OpaqueLSSharedFileListItemRef=}'),
('LSSharedFileListItemResolve', 'i^{OpaqueLSSharedFileListItemRef=}Io^^{__CFURL=}o^{FSRef=[80C]}'),
('LSSharedFileListItemMove', 'i^{OpaqueLSSharedFileListRef=}^{OpaqueLSSharedFileListItemRef=}^{OpaqueLSSharedFileListItemRef=}'),
('LSSharedFileListItemRemove', 'i^{OpaqueLSSharedFileListRef=}^{OpaqueLSSharedFileListItemRef=}'),
('LSSharedFileListInsertItemURL', '^{OpaqueLSSharedFileListItemRef=}^{OpaqueLSSharedFileListRef=}^{OpaqueLSSharedFileListItemRef=}^{__CFString=}^{OpaqueIconRef=}^{__CFURL=}^{__CFDictionary=}^{__CFArray=}'),]
objc.loadBundleFunctions(SFL_bundle, globals(), functions)
# Function names in functions list are now imported and callable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment