Adding App icon to Dock with Packagemaker?

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

  1. macrumors 68030

    Les Kern

    Joined:
    Apr 26, 2002
    Location:
    Alabama
    #1
    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.
     
  2. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #2
    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

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #3
    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
     
  4. thread starter macrumors 68030

    Les Kern

    Joined:
    Apr 26, 2002
    Location:
    Alabama
    #4
    Can't get it to work, but I appreciate YOUR effort.
    lk
     
  5. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #5
    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.
     
  6. thread starter macrumors 68030

    Les Kern

    Joined:
    Apr 26, 2002
    Location:
    Alabama
    #6
    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!
     
  7. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #7
    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.
     
  8. macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #8
    I think killing the dock is fine. The iLife 08 installer does that to add the new iMovie to the dock.
     
  9. thread starter macrumors 68030

    Les Kern

    Joined:
    Apr 26, 2002
    Location:
    Alabama
    #9
    Thanks folks. I'll be making the installer for my "Golden Master" this weekend. Wish me luck, and THANKS.
     
  10. macrumors newbie

    Joined:
    Sep 10, 2007
    #10
    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

    kainjow

    Joined:
    Jun 15, 2000
    #11
    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

    Joined:
    Oct 26, 2007
    #12
    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