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 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 bristow
here (GitHub)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:
$ /absolute/path/for/bristow -u /Applications/Mail.app Desktop/Mail.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 bristow
from a post-installation script, you need to know 2 file paths:
bristow
.
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:
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
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 bristow
tool as an extra resource of the package. Here is how to do that:
You can now build your package and test it.
Copyright 2008-2018 Stéphane Sudre. All rights reserved.