There are no tools provided with the default Mac OS X installation that will let you create an alias from the command line1. So we have to provide our own tool to do that. It just happens that such a tool is available, its name is bristow.

bristow lets you create an alias in the home folder of the current user or all users2 for a file or folder.

You can get the source code for bristowhere (176 KB)3 or you can get an already built executable binary here (28 KB).

Let's say you want to create an alias of the Apple Mail application on your Desktop, here is how you can do this from a Terminal session:

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 bristow from a post-installation script, you need to know 2 file paths:

the path that should be used to call bristow.

the path where the application will be installed.

Since bristow 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 bristow tool, you do not want to use a hard coded path. The application may not always be installed where you think it will be:

you may have allowed the user to install your package on a volume other than the startup disk. In this case, you have no ways to know the name of the destination volume.

you may have attached a locator rule to the application bundle in the payload. In this case, if a previous version of the application is found in another location on the destination volume, the installer will upgrade the previous version with the version in the package.

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

./bristow -u $2 Desktop/MyApplication.app

exit 0

Setting the post-installation script for the application

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:

Select the application in the Files hierarchy list.

Click on the Scripts tab in the inspector.

Click on the Set button for the post-installation script.

Select the script and click Set.

Including the bristow tool in the package

Finally, we will add the bristow tool as an extra resource of the package. Here is how to do that: