Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 在Cocoa中以编程方式向收藏夹添加快捷方式_Macos_Cocoa_Shortcut_Finder - Fatal编程技术网

Macos 在Cocoa中以编程方式向收藏夹添加快捷方式

Macos 在Cocoa中以编程方式向收藏夹添加快捷方式,macos,cocoa,shortcut,finder,Macos,Cocoa,Shortcut,Finder,我已经构建了一个Mac应用程序,我想在安装时在Finder的收藏夹部分添加一个快捷方式。我确实看到其他应用程序实现了同样的功能(比如AirDrop)。如何执行此操作?您可以通过appleScript执行此操作,但这不是最好的方法。(如果将cmd+t更改为其他函数,此操作将失败) 此外,您还可以使用添加项目。谢谢,这很有用,但这只是添加一个文件夹。没有添加一个外部驱动器,这是我所追求的(对不起,不清楚,我在原来的帖子)。 tell application "Finder" activate

我已经构建了一个Mac应用程序,我想在安装时在Finder的收藏夹部分添加一个快捷方式。我确实看到其他应用程序实现了同样的功能(比如AirDrop)。如何执行此操作?

您可以通过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