Mac Adding App icon to Dock with Packagemaker?

Les Kern

macrumors 68040
Original poster
Apr 26, 2002
3,063
76
Alabama
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

macrumors 604
Aug 2, 2002
6,560
628
Cork, Ireland.
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

macrumors 604
Aug 2, 2002
6,560
628
Cork, Ireland.
Ah, just found this on macosxhints.com:

Code:
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
 

whooleytoo

macrumors 604
Aug 2, 2002
6,560
628
Cork, Ireland.
Hmm...

Ok, try this (obviously substituting your application, as necessary) :
Code:
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

macrumors 68040
Original poster
Apr 26, 2002
3,063
76
Alabama
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

macrumors G4
Nov 3, 2005
10,410
10,501
UK
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
Code:
killall "Dock"
to quit the dock, it then automatically restarts.
 

Les Kern

macrumors 68040
Original poster
Apr 26, 2002
3,063
76
Alabama
Thanks folks. I'll be making the installer for my "Golden Master" this weekend. Wish me luck, and THANKS.
 

piersr

macrumors newbie
Sep 10, 2007
1
0
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

Moderator emeritus
Jun 15, 2000
7,958
3
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

macrumors newbie
Oct 26, 2007
1
0
Permissions to the dock.plist?

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!