Installation Q & A
Q
I want to create an alias on the desktop of the user for the application I am installing. How can I do that?
A
This can be achieved through a shell script that will be run after the application has been installed. The shell script will run a command line tool that will create the alias.

This article will describe how to do this with Packages.


Creating an alias from the command line

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


Calling bristow after the application has been installed

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:

  1. Select the application in the Files hierarchy list.
  2. Click on the Scripts tab in the inspector.
  3. Click on the Set… button for the post-installation script.
  4. 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:

  1. Click the Scripts tab.
  2. Click the + button.
  3. Select the bristow tool and click Add…
  4. Click Add.

You can now build your package and test it.


Sample Project
  1. It is possible to create an alias with an AppleScript script but I would not recommend using AppleScript scripts within an installation package.
  2. This can only be done by the super-user (root).
  3. This is an Xcode project that can be built on Mac OS X v10.5 or later.

Site Map

Copyright 2008-2018 Stéphane Sudre. All rights reserved.