【问题标题】:OS X Finder Sync ExtensionOS X Finder 同步扩展
【发布时间】:2015-04-20 17:49:41
【问题描述】:

我无法创建简单的 Finder 同步扩展。

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

终端在运行时显示此内容

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 init] 从 /Users/user/Library/Developer/Xcode/DerivedData/findersynctest-dkyjmfmqzedkquhbhqxejzlzzukn/Build/Products/Debug/findersynctest.app/Contents/PlugIns/pcssyncextension.appex ; 12:36:01 编译

除了创建一个空项目并添加 Finder 同步扩展之外,我还需要做些什么才能使其正常工作?

【问题讨论】:

  • 这似乎是 finder 的间歇性错误 - 使用 force quit 对话框重新启动 finder 将允许扩展程序运行。

标签: objective-c macos finder findersync osx-extensions


【解决方案1】:

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

将项目添加到查找器侧栏

// 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);

从侧边栏中删除项目的代码

// 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 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)

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

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

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

【讨论】:

  • 嗨...我正在尝试一个简单的查找器同步来添加工具栏按钮。它是第一次连接的。当我停止并再次运行时,它说“等待附加”。知道为什么会这样吗?
  • 发生这种情况请确保您启用了扩展程序(参见上面的示例),并确保您在系统偏好设置中启用了它。此外,如果您打开 finder 并转到 View->Customize Toolbar 并确保它已添加,它可能不会添加到您的 finder 窗口中。有一种方法可以以编程方式做到这一点,但我不需要这样做,所以我不确定它是什么
  • 如果我从头开始为 finder sync extn 创建一个 Xcode 项目,并从调试器运行它工作正常。我可以在 Sys Preferences->Extensions 中切换它。但是当我从 XCode 中停止它并尝试再次运行时,它会显示“Waiting to Attach”。我注意到在这种情况下,扩展条目仍然存在于 Sys Preferences->Extensions 中,尽管它没有被选中。有没有办法从扩展中删除它。我尝试从 com.apple.finder.plist 中删除。但是在重新启动时它会再次填充它,不知道从哪里开始。
  • 使用 killall Finder 重新启动 finder 并重新加载扩展。
  • 嘿,我是 mac dev 的新手,根据苹果指南,如果我添加图标,一旦我将文件夹添加到 finder 侧栏,文件夹图标就会改变,但它是不变。你能告诉我怎么做吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-12
  • 2014-09-27
  • 2014-12-13
  • 1970-01-01
  • 1970-01-01
  • 2018-04-28
相关资源
最近更新 更多