PDA

View Full Version : Adding App icon to Dock with Packagemaker?




Les Kern
Aug 20, 2007, 07:02 AM
Wondering if there is a script or method that can place an application's icon on the dock if the user wants one there? I am using PackageMaker 2.0 from Apple's dev tools.
thx.



whooleytoo
Aug 20, 2007, 08:06 AM
I'd guess it's possible using the postflight script, but I'd need to look at the Dock files (using Windows at the mo) to see how. Possibly via AppleScript?

You could use the postflight to launch a small application/applescript to prompt the user, but it might be a bit of a kludge of a design.

You're probably better off just showing the application in the Finder once it's installed, hence the user is likely to launch it. Once it's launched, you can provide a dialog on first launch to ask the user if they'd like the app to remain in the Dock.

whooleytoo
Aug 20, 2007, 08:10 AM
Ah, just found this on macosxhints.com:


defaults write com.apple.dock persistent-apps -array-add '<dict>
<key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString
</key><string>/Path/to/the/Programme.app</string><key>_CFURLStringType
</key><integer>0</integer></dict></dict></dict>'

Obviously, be careful not to install the icon every time the installer runs, or you'll have a Dockful of your-apps!:p

Les Kern
Aug 20, 2007, 11:19 PM
Obviously, be careful not to install the icon every time the installer runs, or you'll have a Dockful of your-apps!:p

Can't get it to work, but I appreciate YOUR effort.
lk

whooleytoo
Aug 20, 2007, 11:50 PM
Hmm...

Ok, try this (obviously substituting your application, as necessary) :

defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Automator.app/</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>";

For me, it works fine, but unfortunately it doesn't take effect until the Dock restarts, such as at login (Try force-quitting the Dock to see if it appears). I don't know of any way of forcing this to take effect immediately, other than killing the Dock.

Les Kern
Aug 21, 2007, 08:02 AM
Hmm...

Ok, try this....

Ya know, it certainly works... Might be able to put in a dock restart on it, but I have to decide this: The app when installed is defaulted to the apps folder, but is changeable. Of course if they DO change it the script won't work. So, do I decide to make it default to the apps folder as a rule? I kind of like that though... my app belongs in Applications. And a nice, simple explanation to the user that the icon will be there on log in is okay.
Choices!

Thanks for that handy bit of code. You went out of your way to help this developer!

Eraserhead
Aug 21, 2007, 08:23 AM
Might be able to put in a dock restart on it, but I have to decide this: The app when installed is defaulted to the apps folder, but is changeable.

You might be able to get the path to the installed directory as a script.

Also once you've added the icon you can use the shell script
killall "Dock" to quit the dock, it then automatically restarts.

Nutter
Aug 21, 2007, 09:48 AM
I think killing the dock is fine. The iLife 08 installer does that to add the new iMovie to the dock.

Les Kern
Aug 21, 2007, 07:20 PM
Thanks folks. I'll be making the installer for my "Golden Master" this weekend. Wish me luck, and THANKS.

piersr
Sep 10, 2007, 09:48 AM
Obviously, be careful not to install the icon every time the installer runs, or you'll have a Dockful of your-apps!:p

Thanks all, this is top notch information! However, I dont want to an install a new icon every time the installer is run, im expecting to do a lot of revisions and updates as i add features/remove bugs from my app.

Any idea how this can be achieved, i cant see an 'array-remove' option in the defaults command.

kainjow
Sep 10, 2007, 01:01 PM
I think killing the dock is fine. The iLife 08 installer does that to add the new iMovie to the dock.

If iLife does it, it probably means that the script is accessible view the post-flight script in the installer package. Someone should check it out :)

kbuller
Oct 26, 2007, 04:25 PM
I've successfully written a script to add icons to the dock. No problem. But when the script is run from the package post install... it kills my dock and replaces it with a generic dock. I believe the problem is that security changes on the com.apple.dock.plist since the installer is being run by root. Anyone else have this problem? Know a way around it?

Thanks for you help!