/Applications
and ~/Documents
at the same time?Yes, you can but, in most cases, you probably shouldn't.
Before looking at how this can be achieved, let's take some time to see why you probably shouldn't try to install in both /Applications
and ~/Documents
at the same time:
~/Documents
are templates, why not install them in /Library/Application Support/MyApplication/Templates
so that any user account can see them?~/Documents
are default preferences for an application, couldn't it be possible for the application to define these default preferences on its first launch?
If you're still convinced that you need to install both in /Applications
and ~/Documents
at the same time, this can be done using 2 solutions:
First solution: Install everything in /
and then move the appropriate items to ~/Documents
The installation procedure would proceed like this:
/
.~/Documents
and fix the owner, group and permissions using a post-installation script.What we need to do is to:
/Applications
to the / ▸ Applications folder in the Payload hierarchy.~/Documents
to the / ▸ Users ▸ Shared folder in the Payload hierarchy. Better: add them to
/ ▸ Users ▸ Shared ▸ ACustomFolderName.#!/bin/sh
DESTINATION_PATH="${HOME}/Documents"
/usr/bin/su $USER -c "/bin/cp /Users/Shared/_Temporary_/MyDocument ${DESTINATION_PATH}"
/bin/rm -f "/Users/Shared/_Temporary_/MyDocument"
/bin/rmdir "/Users/Shared/_Temporary_"
/usr/sbin/chown $USER:staff "${DESTINATION_PATH/MyDocument}"
exit 0
Pros:
Cons:
Installer.app
.~/
, you will need to revisit your post-installation script accordingly.~/
, you will need to revisit your post-installation script accordingly.ACustomFolderName
already exists and contains some other items, these items will be moved to ~/Documents
by the post-installation script.
Better solution: Install the appropriate items in /Applications
and then install the remaining items in ~/Documents
The installation procedure would proceed like this:
/Applications
.~/Documents
through a post-installation script.What we need to do is to:
~/Documents
to the / ▸ Documents folder of the payload hierarchy./Applications
to the / ▸ Applications folder of the payload hierarchy.#!/bin/sh
/usr/bin/su $USER -c "/usr/sbin/installer -pkg ./HomeFolderDistribution.pkg -target CurrentUserHomeDirectory"
exit 0
Pros:
~/
just requires to add new items to the payload of the HomeFolderDistribution distribution project and rebuild both projects.Cons:
Installer.app
since we're actually installing items when running the post-installation script.
Bonus Track: Installing the items in ~/Documents
only during the first installation
Based on a few requests I received in the past, and which is the reason why I'm writing this Q&A in the first place, people who want to install both
in /Applications
and ~/
also want the items in ~/
not to be overwritten when the items in /Applications
are updated by a more recent version of the installation package.
Good news, this can be achieved by modifying the distribution project a bit. We're going to modify the Better solution project. But you could adopt the same type of improvement for the first solution.
The idea is to use a separate package to install the distribution that contains the payload for the ~/Documents folder. And we will attach a requirement to the choice representing this package so that the package is not selected when the myDocument file already exists in its final destination.
What we need to do is to:
myDocument
file exists in the ~/Documents
folder.#!/bin/sh
if [ -f "$HOME/Documents/myDocument" ]; then
exit 1
fi
exit 0
Et voilà !
Revision History | |
---|---|
10/29/19 | First version |
Copyright 2019 Stéphane Sudre. All rights reserved.