【问题标题】:Adding an item to sidebar by editing com.apple.sidebarlists.plist using objective C通过使用目标 C 编辑 com.apple.sidebarlists.plist 将项目添加到侧边栏
【发布时间】:2011-08-17 10:08:40
【问题描述】:

我有一个应用程序,它必须在安装时显示在 Finder 侧边栏的用户列表中。

所以在安装代码上,我又向Library -> Preferences-> com.apple.sidebarlists.plist. 添加了一个字典对象。 即,在 plist 的useritems -> customListItems 中。

如果我看到 plist 添加一切看起来都是正确的。

在重新启动 Finder.app 时,预计会将该项目添加到 Finder 的侧栏中。但我看不到发生任何变化,而是 plist 被旧项目覆盖。我尝试破坏 Finder 缓存并运行代码。仍然没有运气:(请指出我所缺少的东西。 提前致谢!

【问题讨论】:

  • 尝试在分布式通知中心收听所有可能的通知。当项目被添加到列表/从列表中删除时,也许 finder 会收到某种通知。因此,在将条目添加到 plist 后,您应该发送相同的通知(如果有的话)。
  • 谢谢艾曼塔斯。我只是尝试在手动将侧边栏项目添加到 Finder 以及将项目添加到 plist 时捕获所有通知。但在这两种情况下,我都看不到任何通知正在发送。但是当我尝试重新启动 Finder.app 时,在恢复侧边栏时会触发一个名为 com.apple.Finder.LaunchNotification 的通知。一点头绪都没有。注意:我使用的是雪豹。

标签: objective-c


【解决方案1】:

使用 LSSharedFileList。 将项目添加到 Finder/保存对话框侧边栏

-(void) addPathToSharedItem:(NSString *)path
{
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:path]; 

// Create a reference to the shared file list.
LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL,
                                                           kLSSharedFileListFavoriteItems, NULL);
if (favoriteItems) {
    //Insert an item to the list.
    LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems,
                                                                 kLSSharedFileListItemLast, NULL, NULL,
                                                                 url, NULL, NULL);
    if (item){
        CFRelease(item);
    }
}   

CFRelease(favoriteItems);
}  

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 2021-09-25
    • 2010-12-05
    • 2018-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 2020-03-29
    相关资源
    最近更新 更多