Macos 以编程方式在安装时将应用程序图标添加到停靠

Macos 以编程方式在安装时将应用程序图标添加到停靠,macos,package,dmg,Macos,Package,Dmg,我想在安装包(DMG)后自动将我的应用程序添加到dock 有人知道怎么做吗?Andrew,有几种方法可以做到这一点,这在很大程度上取决于您如何安装应用程序 如果您使用PackageMaker安装应用程序,您可以运行“postflight”脚本,将应用程序图标添加到dock的“默认设置”(即首选项)中 如果您没有使用PackageMaker,那么您可能必须在应用程序中运行一个Applescript,该脚本执行相同的“默认”编写技巧 在这两种情况下,您都需要关闭dock(或Finder?)并重新启动

我想在安装包(DMG)后自动将我的应用程序添加到dock


有人知道怎么做吗?

Andrew,有几种方法可以做到这一点,这在很大程度上取决于您如何安装应用程序

如果您使用PackageMaker安装应用程序,您可以运行“postflight”脚本,将应用程序图标添加到dock的“默认设置”(即首选项)中

如果您没有使用PackageMaker,那么您可能必须在应用程序中运行一个Applescript,该脚本执行相同的“默认”编写技巧


在这两种情况下,您都需要关闭dock(或Finder?)并重新启动它,以便获取并显示更改。

我建议您运行以下AppleScript代码,用要添加到de dock的应用程序替换
myapp
,包括其路径

在下面的示例中,我添加了系统应用程序“系统首选项”,但您可以对自己的路径执行相同的操作,只需将应用程序的路径指定给
myapp
变量即可

 on run
   set myapp to "/Applications/System Preferences.app"
   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>" & myapp & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
   try
     tell application "Dock" to activate
   end try
 end run

Michael,我不想在我的应用程序中运行applescript。我想在将我的应用程序复制到应用程序文件夹后立即将其添加到dock bar。这可能吗?请看我为什么评论“这取决于您如何安装应用程序”?如果这是一个拖放安装,没有“触发器”,您可以从DMG自动启动,以实现这一点。您必须在应用程序中执行dock图标Applescript操作,或者您需要使用安装程序,然后使用postflight脚本技巧。
#!/bin/bash
myapp="//Applications//System Preferences.app"
defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$myapp</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
osascript -e 'tell application "Dock" to quit'
osascript -e 'tell application "Dock" to activate'