在Cocoa / XCode中以编程方式添加收藏夹的快捷方式

时间:2013-01-11 15:18:22

标签: xcode macos cocoa

我已经构建了一个Mac App,我想在安装时在Finder的收藏夹部分添加一个快捷方式。我找不到有关如何执行此操作的文档,但我确实看到其他应用程序实现相同的功能(例如AirDrop)。有没有人有任何想法如何做到这一点?

1 个答案:

答案 0 :(得分:0)

你可以通过appleScript来实现,但这不是最好的方法。(如果将cmd + t更改为其他功能,则会失败)

tell application "Finder"
    activate
    -- Select the path you want on the sidebar in the Finder
    select folder "Preferences" of folder "Library" of (path to home folder)
    tell application "System Events"
        -- Command-T adds the Documents Folder to the sidebar
        keystroke "t" using command down
    end tell
end tell

此外,您可以使用LSSharedFileList添加项目。