Objective c 如何使用用户';s最喜欢的文件夹

Objective c 如何使用用户';s最喜欢的文件夹,objective-c,cocoa,directory,favorites,Objective C,Cocoa,Directory,Favorites,我是Mac编程新手,所以如果我的问题太傻,请原谅我 我正在编写一个小应用程序,需要在其中设置一个目标文件夹。 我认为,Firefox或Safari在其“另存为…”对话框中采用的方法是一种非常用户友好的方法,而不仅仅是使用NSButton“选择文件夹” 使用nspoupbutton,可以从用户的收藏夹或上次使用的文件夹中选择文件夹。此外,我还将添加一个最顶级的条目“Choose…”,打开NSOpenPanel 我的问题是:如何获取用户最喜欢的文件夹(例如在Finder应用程序中显示),并用它们填充

我是Mac编程新手,所以如果我的问题太傻,请原谅我

我正在编写一个小应用程序,需要在其中设置一个目标文件夹。 我认为,Firefox或Safari在其“另存为…”对话框中采用的方法是一种非常用户友好的方法,而不仅仅是使用
NSButton
“选择文件夹”

使用
nspoupbutton
,可以从用户的收藏夹或上次使用的文件夹中选择文件夹。此外,我还将添加一个最顶级的条目“Choose…”,打开
NSOpenPanel

我的问题是:如何获取用户最喜欢的文件夹(例如在Finder应用程序中显示),并用它们填充我的
nspoupbutton

以下是它在Firefox中的外观:

您可以在Application Services框架内找到相关功能,您可以获得如下项目列表:

LSSharedFileListRef favorites = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
CFArrayRef snapshot = LSSharedFileListCopySnapshot(favorites, NULL);

CFIndex snapshotCount = CFArrayGetCount(snapshot);
for (CFIndex i = 0; i < snapshotCount; ++i) {
    LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(snapshot, i);
    CFURLRef itemURL = NULL;
    LSSharedFileListItemResolve(item, kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes, &itemURL, NULL);

    NSLog(@"%@", itemURL);
    if (itemURL != NULL) {
        CFRelease(itemURL);
    }
}
CFRelease(snapshot);
CFRelease(favorites);
对应于:


为什么不使用
NSOpenPanel
本身呢?我认为,除了像Yuji明智地建议的那样合并“
NSOpenPanel
”之外,Finder没有任何方法、AppleEvents或API将收藏夹和最新内容列表公开给其他应用程序。
nwnode://domain-AirDrop
file://localhost/Applications/
file://localhost/System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries/myDocuments.cannedSearch/
file://localhost/Users/dave/
file://localhost/Users/dave/Desktop/
file://localhost/Users/dave/Developer/
file://localhost/Users/dave/Documents/
file://localhost/Users/dave/Downloads/
file://localhost/Users/dave/Dropbox/