-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1082 from cozy-labs/macos-favorite-python
Bring back synced dir in Finder's favorite items on macOS
- Loading branch information
Showing
4 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/python | ||
|
||
from Cocoa import NSURL | ||
from CoreFoundation import CFArrayGetCount, CFArrayGetValueAtIndex, kCFAllocatorDefault | ||
from Foundation import NSBundle | ||
from LaunchServices import kLSSharedFileListFavoriteItems | ||
from objc import loadBundleFunctions | ||
from sys import argv | ||
|
||
# For some reason, these functions cannot be imported directly and must be | ||
# manually loaded from the SharedFileList bundle | ||
SFL_bundle = NSBundle.bundleWithIdentifier_('com.apple.coreservices.SharedFileList') | ||
functions = [ | ||
('LSSharedFileListCreate', '^{OpaqueLSSharedFileListRef=}^{__CFAllocator=}^{__CFString=}@'), | ||
('LSSharedFileListCopySnapshot', '^{__CFArray=}^{OpaqueLSSharedFileListRef=}o^I'), | ||
('LSSharedFileListInsertItemURL', '^{OpaqueLSSharedFileListItemRef=}^{OpaqueLSSharedFileListRef=}^{OpaqueLSSharedFileListItemRef=}^{__CFString=}^{OpaqueIconRef=}^{__CFURL=}^{__CFDictionary=}^{__CFArray=}'), | ||
('kLSSharedFileListItemBeforeFirst', '^{OpaqueLSSharedFileListItemRef=}'), | ||
] | ||
loadBundleFunctions(SFL_bundle, globals(), functions) | ||
|
||
# The path to added to the Finder's favorites | ||
path = argv[1] | ||
|
||
# Make it an URL object (which is a valid favorite item) | ||
item = NSURL.alloc().initFileURLWithPath_(path) | ||
|
||
# Retrieve the favorite items list | ||
favorite_items = LSSharedFileListCreate(kCFAllocatorDefault, | ||
kLSSharedFileListFavoriteItems, None) | ||
|
||
# Add the item to the top of the list | ||
LSSharedFileListInsertItemURL(favorite_items, kLSSharedFileListItemBeforeFirst, | ||
None, None, item, None, None) |
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