Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created February 20, 2012 15:52
Show Gist options
  • Save talkingmoose/1869808 to your computer and use it in GitHub Desktop.
Save talkingmoose/1869808 to your computer and use it in GitHub Desktop.
Shell script to ditto Apple package payload to user home folders and user template
#!/bin/sh
## postflight
copyPayloadToAllUsers() {
# Enter a path to a logfile.
LOGFILE="/path/to/file.log"
# Copy the payload file(s) to all existing user folders.
cd /Users
for AUSER in *
do
if [ ! $AUSER = "Shared" ] ; then
ditto /path/to/file.txt /Users/$AUSER/path/to/folder/
if [ $? = 0 ] ; then
date "+%A %m/%d/%Y %H:%M:%S Payload copied to user folder $AUSER." >> $LOGFILE
else
date "+%A %m/%d/%Y %H:%M:%S ERROR! Unable to copy payload to user folder $AUSER." >> $LOGFILE
fi
fi
done
}
copyPayloadToUserTemplate() {
# Copy the payload file(s) to the User Template folder.
ditto /path/to/file.txt /System/Library/User\ Template/English.lproj/path/to/folder/
if [ $? = 0 ] ; then
date "+%A %m/%d/%Y %H:%M:%S Payload copied to User Template folder." >> $LOGFILE
else
date "+%A %m/%d/%Y %H:%M:%S ERROR! Unable to copy payload to User Template folder." >> $LOGFILE
fi
}
copyPayloadToAllUsers
copyPayloadToUserTemplate
exit 0
@talkingmoose
Copy link
Author

Instructions:

  1. Create a new Apple Installer package that deploys its payload to a temporary location such as /private/tmp/.
  2. Modify "/path/to/file.txt" in the script to reference the deployed payload file.
  3. Modify "/path/to/folder/" to reference the location of the copied files.
  4. Modify "/path/to/file.log" to reference a log file for messages from the script.
  5. Add the modified script as a postflight script to the Apple Installer package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment