OS X Finder同步扩展 [英] OS X Finder Sync Extension

查看:228
本文介绍了OS X Finder同步扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法创建简单的Finder同步扩展程序.

I am not able to create a simple Finder Sync Extension.

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

I have created a new OS X project and added the Finder Sync Extension target and I ran the extension attached to finder. The code appears to be running the init methods and the toolbar items methods are getting called but nothing is displaying in finder.

终端在运行时显示此信息

The terminal is showing this when it runs

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)的(视图)出口:丢失 设置器或实例变量2015-04-20 12:45:58.887 pcssyncextension [3196:62451]-[FinderSync初始化]从以下位置启动 /Users/用户/库/开发人员/Xcode/DerivedData/findersynctest-dkyjmfmqzedkquhbhqxejzlzzukn/Build/Products/Debug/findersynctest.app/Contents/PlugIns/pcssyncextension.appex ;编译于12:36:01

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

除了创建一个空项目并添加Finder Sync Extension之外,还有其他需要做的工作吗?

Is there anything else I need to do to get this to work other that just creating an empty project and adding the Finder Sync Extension?

推荐答案

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

I was able to find a few things that helped me. By default the toolbar item is not added to the finder window unless the user drags it in. I was not able to find a way to programmatically add the item to the finder window toolbar.

将项目添加到取景器侧栏中

Add Item to the finder side 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 Item From 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);

在Finder中重新加载目录

Reload 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];

启用扩展程序的代码(捆绑ID)

Code to Enable Extension (bundle ID)

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

禁用扩展程序的代码(捆绑ID)

Code to Disable Extension (bundle ID)

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

这篇关于OS X Finder同步扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆