This article will describe how to do this with Packages.
There are no tools provided with the default Mac OS X installation that will let you add an application to the Dock from the command line. So we have to provide our own tool to do that. It just happens that such a tool is available, its name is emmett
.
emmett
lets you add an application, a file or a folder to the Dock of the current user.
You can get the source code for emmett
here (GitHub).
Let's say you want to add the Dictionary application to your Dock, here is how you can do this from a Terminal session:
$ /absolute/path/for/emmett add /Applications/Dictionary.app
It is possible to run a shell script after a bundle application within the payload has been installed. Such a script is called a post-installation script.
In order to run emmett
from a post-installation script, you need to know 2 file paths:
emmett
.
Since emmett
is not part of a standard installation, you will need to also include it in the extra resources of the package. During the installation process, extra resources are extracted at the same level as the post-installation script.
When it comes to the installation path of the application to pass to the emmett
tool, you do not want to use a hard coded path. The application may not always be installed where you think it will be:
Fortunately, when the installer runs a post-installation script attached to an application bundle, it provides you with the final installation location for the application as a parameter. For a shell script, this is the $2 parameter.
Knowing all this, we can now write our shell script. Assuming the name of the application to install is MyApplication, here is what the script will look like:
#!/bin/sh
# We only install the application in the Dock for the current user and when the installation is not run from the command line.
if [ "$COMMAND_LINE_INSTALL" = "" ]; then
/usr/bin/su $USER -c "./emmett add $2"
fi
exit 0
As we mentionned earlier, we will attach the post-installation script to the application - and not set it to be the post-installation script for the package -. Here is how to do that:
Finally, we will add the emmett
tool as an extra resource of the package. Here is how to do that:
You can now build your package and test it.
Copyright 2012-2018 Stéphane Sudre. All rights reserved.