OSX Finder Sync Extension

I cannot create a simple extension string Finder Sync.

I created a new OS X project and added the Finder Sync Extension target, and I launched the extension attached to finder. In the code, the init methods seem to be running, and the toolbar element methods are called, but nothing is displayed in the finder.

The terminal shows this when it starts

2015-04-20 12: 45: 52.700 pcssyncextension [3196: 62451] Failed to connect (colorGridView) from (NSApplication) to (NSColorPickerGridView): setter or instance parameter missing 2015-04-20 12: 45: 52.701 pcssyncextension [3196: 62451] Failed to connect (view) from (NSApplication) to (NSColorPickerGridView): there is no setter or instance variable 2015-04-20 12: 45: 58.887 pcssyncextension [3196: 62451] - [FinderSync init] started with / Users / user / Library / Developer / Xcode / DerivedData / findersynctest -dkyjmfmqzedkquhbhqxejzlzzukn / Build / Products / Debug / findersynctest.app / Contents / PlugIns / pcssyncextension.appex; compiled at 12:36:01

Is there anything else I need to do to get this to work differently, just by creating an empty project and adding the Finder Sync extension?

+3
source share
1 answer

I managed to find a few things that helped me. By default, a toolbar item is not added to the search box unless the user drags it. I could not find a way to programmatically add an item to the search box toolbar.

Add item to search bar

// Create a reference to the shared file list. LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL); // Check Items if (favoriteItems) { // Get CFURL for Application CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path]; // Add Item LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, url, NULL, NULL); // Release if (item) CFRelease(item); } // Release if (favoriteItems != NULL) CFRelease(favoriteItems); 

Code to remove an item from the sidebar

 // Create a reference to the shared file list. LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL); // Check Items if (favoriteItems) { // Get Login Items CFArrayRef favoriteItemsArray = LSSharedFileListCopySnapshot(favoriteItems, NULL); // Loop Through Items for (id item in (__bridge NSArray *)favoriteItemsArray) { // Get Item Ref LSSharedFileListItemRef itemRef = (__bridge LSSharedFileListItemRef)item; // Get Item URL CFURLRef itemURL = LSSharedFileListItemCopyResolvedURL(itemRef, kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes, NULL); if (itemURL != NULL) { // If Item Matches Remove It if ([[(__bridge NSURL *)itemURL path] hasPrefix:path]) LSSharedFileListItemRemove(favoriteItems, itemRef); // Release if (itemURL != NULL) CFRelease(itemURL); } } // Release if (favoriteItemsArray != NULL) CFRelease(favoriteItemsArray); } // Release if (favoriteItems != NULL) CFRelease(favoriteItems); 

Update directory in Finder

 // Reload Finder (change the word directory to file if updating file) NSAppleScript * update = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Finder\" to update POSIX directory \"%@\"",path]]; [update executeAndReturnError:nil]; 

Code to enable the extension (package identifier)

 system("pluginkit -e use -i com.mycompany.finderExt") 

Code to disable the extension (package identifier)

 system("pluginkit -e ignore -i com.mycompany.finderExt") 
+8
source

Source: https://habr.com/ru/post/1232954/


All Articles