RE: Ehh, what's up Dock?
HI, Can I package the dockutil application in our products and distribute? Regards Prema -----Original Message----- From: installer-dev-bounces+prema.kumar=efi.com@lists.apple.com [mailto:installer-dev-bounces+prema.kumar=efi.com@lists.apple.com] On Behalf Of Stuart Ramdeen Sent: Friday, March 09, 2012 4:19 PM To: Stephane Sudre Cc: Installer-Dev mailing-list Subject: Re: Ehh, what's up Dock? Brilliant post. Thanks for putting the effort in, I'm sure emmett will come in handy. Sent from my Spectrum +3 On 9 Mar 2012, at 00:20, Stephane Sudre <dev.iceberg@gmail.com> wrote:
A question that comes from time to time on this list is:
How do I add my application to the Dock?
Here is a beginning of an answer.
Foreword --------
Installing items into the user's Dock is either considered bad or OK. Personally, I don't care who's right or wrong for the following reasons: people complaining about installers adding items into the Dock (because it's not the way to do it on the Mac) are the same ones who will tell you that iWorks is a great office suite. Guess which office suite from a Californian company whose name starts with the letter A is installing its applications into the Dock upon installation. Let's also forget what happens when you download an application from the Mac App Store on Mac OS X v10.6.8.
The Problem -----------
You would like to install your application into the Dock upon installation. While it's easy to do it with a mouse (or trackpad), it's not so easy to automate this.
As far as I know there is no command line tool in a standard Mac OS X system to do this. And there is, for instance, no such action in PackageMaker.
Facts -----
o The list of items of the Dock is saved in the preferences file of the Dock in ˜/Library/Preferences/com.apple.dock.plist.
o The format of this property list is something like this:
<dict> <key>persistent-apps</key> <array> <dict> <key>GUID</key> <integer></integer> <key>tile-data</key> <dict> <key>file-data</key> <dict> <key>_CFURLAliasData</key> <data></data> <--- AliasHandle data <key>_CFURLString</key> <string></string> <--- Absolute file path or URL <key>_CFURLStringType</key> <integer></integer> <--- Path type (0: path / 15: URL) </dict> <key>file-label</key> <string></string> <key>file-mod-date</key> <integer></integer> <--- UTCDate <key>file-type</key> <integer></integer> <key>parent-mod-date</key> <integer></integer> <--- UTCDate </dict> <key>tile-type</key> <string>file-tile</string> </dict> ... </array> <key>peristent-others</key> <array> ... </array> ... </dict>
Cheap Solutions ---------------
o #1: Use the defaults command like too to edit the com.apple.dock.plist file.
This makes sense since, after all, you are looking into modifying the preferences of the Dock application.
An example showing how to do this is available on the Mac OS X Hints web site:
http://hints.macworld.com/article.php?story=20040819170450489
$ 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/Program.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
Followed by:
$ killall Dock
to reflect the change in the Dock.
This probably works fine in most cases and on most Mac OS X versions. I haven't tried it myself.
o #2: Edit the plist file directly.
This still makes sense since after all you are editing a property list file. The issue is that there's no command line tool available in a standard Mac OS X system to do this. You either need to write your own, include another one or dig into an Apple installation package using one and borrow it or use some features of a scripting language.
Again, after editing the file, you will call:
$ killall Dock
to reflect the change in the Dock.
Why do I label these solutions as cheap?
3 reasons:
- Though the Dock seems to accept new entries with a bunch of missing key-values, it's not ideal to have really inconsistent entries into the Dock preferences. And good luck with computing the AliasHandle or the modification UTCDate of a file from the command line.
- As mentioned in the short Facts paragraph, a file can be referenced by either an absolute path or URL. Starting with Mac OS X Lion, the _CFURLString regular entries look like this: file://localhost/a/path. The defaults or plist editing solution usually still set _CFURLString as /a/path
- Calling killall Dock is a bit violent. And Apple does not do it like this in the iWork '09 installer. They first send a quit Apple Event to the Dock, then wait for the Dock to be relaunched, then stop (SIGSTOP) the Dock process, make the modifications and then resume (SIGCONT) the process and then kill it. There must be a reason for that.
Less Cheap Solutions --------------------
o #1: Use dockutil
It's somehow funny that when you google for "add items to the dock" you don't get dockutil as the top result. Because it's a very good solution for this.
As mentioned on its dedicated web page (http://code.google.com/p/dockutil/), dockutil is a command line utility for managing Mac OS X dock items. It works on Mac OS X v10.4, v10.5. I tried it successfully on Mac OS X v10.6 and v10.7. I also tried it on the next version of Mac OS X but I can't talk about it. You will need to try it on your side to know whether it still works or not.
Using dockutil is easy. You do not have to re-invent the wheel, you just call:
dockutil --add /Applications/MyApp.app
and that's all.
It will add entries that are more complete than the cheap solutions (it takes care of the file://localhost/ vs / case).
It will kill the Dock for you.
It has a lot of options (not to kill the Dock for instance).
It's free and available under the Apache 2.0 license.
o #2: Use emmett
emmett is a command line tool I wanted to write for a while and finally had some spare time to do it. I didn't know about the dockutil tool before I had almost completed writing emmett and was checking if the "dockutil" name was already used. emmett works on Mac OS X v10.5 and later.
http://s.sudre.free.fr/Software/DevPotPourri.html
Using emmett is also easy.
emmett add /Applications/MyApp.app
That's all.
It will add entries that are even more complete than the ones made by dockutil. It also kill the Dock for you (but not with a killall, it does it the way the iWork installer does it).
It has a few options (not to kill the Dock for instance).
It's free and available under the BSD license (the Obj-C/Foundation source code is also available under the BSD license).
Integration into an installation package ----------------------------------------
You can find an example using emmett that covers that for Packages here:
http://s.sudre.free.fr/Software/Packages/Q&A_2.html
If you are using PackageMaker, you can probably get some inspiration from it.
Hope it can help. If you spot an error, don't hesitate to report it.
_______________________________________________ Do not post admin requests to the list. They will be ignored. Installer-dev mailing list (Installer-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/installer-dev/stuart%40toucancomputi...
This email sent to stuart@toucancomputing.co.uk
_______________________________________________ Do not post admin requests to the list. They will be ignored. Installer-dev mailing list (Installer-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/installer-dev/prema.kumar%40efi.com This email sent to prema.kumar@efi.com Confidentiality notice: This message may contain confidential information. It is intended only for the person to whom it is addressed. If you are not that person, you should not use this message. We request that you notify us by replying to this message, and then delete all copies including any contained in your reply. Thank you. _______________________________________________ Do not post admin requests to the list. They will be ignored. Installer-dev mailing list (Installer-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/installer-dev/site_archiver%40lists.... This email sent to site_archiver@lists.apple.com
participants (1)
-
Prema Kumar