【问题标题】:Adding shortcut to favorites programmatically in Cocoa [duplicate]在 Cocoa 中以编程方式添加收藏夹的快捷方式 [重复]
【发布时间】:2013-01-11 15:18:21
【问题描述】:

我已经构建了一个 Mac 应用程序,我想在安装时在 Finder 的收藏夹部分中添加一个快捷方式。我确实看到其他应用程序实现了同样的事情(例如 AirDrop)。我该怎么做?

【问题讨论】:

    标签: macos cocoa shortcut finder


    【解决方案1】:

    你可以通过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 添加项目。

    【讨论】:

    • 谢谢,这很有用,但这只是添加一个文件夹。不添加我所追求的外部驱动器(抱歉,我在原始帖子中不清楚)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多