1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Adding App icon to Dock with Packagemaker?

Discussion in 'Mac Programming' started by Les Kern, Aug 20, 2007.

  1. macrumors 68030

    Les Kern

    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.
  2. macrumors 603


    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.
  3. macrumors 603


    Ah, just found this on macosxhints.com:

    defaults write com.apple.dock persistent-apps -array-add '<dict>
    Obviously, be careful not to install the icon every time the installer runs, or you'll have a Dockful of your-apps!:p
  4. macrumors 68030

    Les Kern

    Can't get it to work, but I appreciate YOUR effort.
  5. macrumors 603



    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.
  6. macrumors 68030

    Les Kern

    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.

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


    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.
  8. macrumors 6502

    I think killing the dock is fine. The iLife 08 installer does that to add the new iMovie to the dock.
  9. macrumors 68030

    Les Kern

    Thanks folks. I'll be making the installer for my "Golden Master" this weekend. Wish me luck, and THANKS.
  10. macrumors newbie

    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.
  11. Moderator emeritus


    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 :)
  12. macrumors newbie

    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!

Share This Page