I would like my application to be automatically added to the dock after the package (DMG) is installed?
Does anyone know how to do this?
I would like my application to be automatically added to the dock after the package (DMG) is installed?
Does anyone know how to do this?
There's a couple ways to do this, Andrew, and a lot of this depends on how you're doing your application installing.
If you are using PackageMaker to install your app, you can run a "postflight" script which adds your app's icon to the "defaults" (i.e. the preferences) of the dock. This older MacRumors thread shows how to do that.
If you are not using PackageMaker, then you might have to run an Applescript from within your app that does the same "defaults" writing trick. Here's a thread on AskDifferent that shows how.
In both cases you need to kill the dock (or Finder?) and restart it in order to get the change to pick up and show.
I would suggest you run the following AppleScript code, replacing myapp
with the app you want to add to de dock, including its path.
In the example below, I am adding the system app "System Preferences", but you can do the same with your own path, just assign the path of your app to the myapp
variable.
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
This follows the suggestion given by Michael, but it should be more gentle as it just quits the Dock rather thank killing it.
If you prefer bash, you could run the following code, again assigning the path of your own app to the myapp
variable.
Note: in the bash case, you have to use double slashes when specifying your the path, as you can see in the example.
#!/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'