以编程方式将Web应用程序快捷方式添加到macOS Dock

时间:2019-04-15 20:23:36

标签: macos dock

我正在以编程方式将应用程序图标添加到Dock中。但是我发现的所有信息都表明,更改后我需要重新启动Dock。

是否有任何可能的方法可以将图标添加到Dock的“活动”中而无需杀死Dock进程?我也许可以使用Mach IPC吗?

1 个答案:

答案 0 :(得分:0)

我找到了以下AppleScript。它适用于我的系统。

my add_item_to_dock(choose file of type {"APPL"} with prompt "Choose an application to add to the Dock:")
on add_item_to_dock(item_path)
    try
        get item_path as alias -- you need a POSIX path so this coerces the path in case it's an HFS path, alias, file ref, etc.
        set item_path to POSIX path of item_path
    end try
    try
        tell application "Dock" to quit
    end try
    do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & item_path & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
    try
        tell application "Dock" to activate
    end try
end add_item_to_dock

该条目将存储在〜/ Library / Preference / com.apple.cock.plist

希望这会有所帮助。