OS X Finder同步扩展

Dou*_*obb 3 macos finder objective-c findersync osx-extensions

我无法创建简单的Finder Sync Extension.

我创建了一个新的OS X项目并添加了Finder Sync Extension目标,并运行了附加到finder的扩展.代码似乎正在运行init方法,并且工具栏项方法被调用但查找器中没有显示任何内容.

终端在运行时显示此信息

2015-04-20 12:45:52.700 pcssyncextension [3196:62451]无法连接(colorGridView)插座(NSApplication)到(NSColorPickerGridView):缺少setter或实例变量2015-04-20 12:45:52.701 pcssyncextension [3196 :62451]无法从(NSApplication)连接(查看)插座到(NSColorPickerGridView):缺少setter或实例变量2015-04-20 12:45:58.887 pcssyncextension [3196:62451] - 从/ Users /启动[FinderSync init] user/Library/Developer/Xcode/DerivedData/findersynctest-dkyjmfmqzedkquhbhqxejzlzzukn/Build/Products/Debug/findersynctest.app/Contents/PlugIns/pcssyncextension.appex; 编译于12:36:01

除了创建一个空项目并添加Finder Sync Extension之外,还有什么我需要做的才能让它工作吗?

Dou*_*obb 9

我找到了一些帮助我的东西.默认情况下,除非用户将其拖入,否则工具栏项不会添加到查找器窗口.我无法找到以编程方式将项添加到查找器窗口工具栏的方法.

将项目添加到取景器侧栏

// 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);
Run Code Online (Sandbox Code Playgroud)

从侧边栏删除项目的代码

// 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);
Run Code Online (Sandbox Code Playgroud)

在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];
Run Code Online (Sandbox Code Playgroud)

代码启用扩展(包ID)

system("pluginkit -e use -i com.mycompany.finderExt")
Run Code Online (Sandbox Code Playgroud)

代码禁用扩展(包ID)

system("pluginkit -e ignore -i com.mycompany.finderExt")
Run Code Online (Sandbox Code Playgroud)

  • 使用killall Finder重新启动finder并重新加载扩展. (2认同)