Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created May 5, 2023 15:33
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save talkingmoose/3926e86332e32eb7d05a161c3f7e8f69 to your computer and use it in GitHub Desktop.
This script when edited with the Apple Installer package name and app bundle identifier(s) will deploy a choices.xml file to exlude an installer choice during package installation.
#!/bin/zsh
:<<ABOUT_THIS_SCRIPT
-----------------------------------------------------------------------
Written by:William Smith
Partner Program Manager
Jamf
bill@talkingmoose.net
https://gist.github.com/talkingmoose/3926e86332e32eb7d05a161c3f7e8f69
Originally posted: May 5, 2023
Purpose: Deploys a Choices XML file for use with the specified Apple
Installer package.
Instructions:
1. Create a new script in Jamf Pro with the entirety of
this script.
2. Edit the installerPackage name on line 45 with the name of the
Apple installer package you're deploying.
3. Edit the app bundle identifier on line 59 with the CFBundleIdentifier
of the app you wish to prevent installing. To add a second app,
duplicate the entire dictionary ( from <dict> to </dict> )
and edit its choiceIdentifier string.
4. In a new Jamf Pro policy, add both the package and the script.
5. Set the package to Cache not Install.
6. Add any additional policy settings you need, scope, and deploy.
Except where otherwise noted, this work is licensed under
http://creativecommons.org/licenses/by/4.0/
“A problem well stated is a problem half solved."
-----------------------------------------------------------------------
ABOUT_THIS_SCRIPT
# provide the name of an Apple Installer package file that supports Choices XML
installerPackage="Microsoft_365_and_Office_16.72.23040900_Installer.pkg"
# modify the choiceIdentifier string with the app identifier (CFBundleIdentifier) to exclude from installation
# duplicate the full dictionary to include additiona apps
choicesXML='<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>attributeSetting</key>
<integer>1</integer>
<key>choiceAttribute</key>
<string>selected</string>
<key>choiceIdentifier</key>
<string>com.microsoft.onenote.mac</string>
</dict>
</array>
</plist>'
function logmessage() {
if [ $? = 0 ] ; then
echo "$1"
else
echo "$2"
echo "Aborting script"
cleanup
exit 1
fi
}
function cleanup() {
/bin/rm -Rf "$tempDirectory"
logmessage "Removed temporary items." "Failed removing temporary items."
/bin/rm -f "/Library/Application Support/JAMF/Waiting Room/$installerPackage" && /bin/rm -Rf "/Library/Application Support/JAMF/Waiting Room/$installerPackage.cache.xml"
logmessage "Removed TeamViewer Host package and supporting files from Jamf Waiting Room." "Failed Removing TeamViewer Host package and supporting files from Jamf Waiting Room."
}
# create temporary working directory
workDirectory=$( /usr/bin/basename $0 )
tempDirectory=$( /usr/bin/mktemp -d "/private/tmp/$workDirectory.XXXXXX" )
logmessage "Created working directory '$tempDirectory'." "Failed to create working directory '$tempDirectory'."
# change directory to temporary working directory
cd "$tempDirectory"
logmessage "Changed directory to working directory '$tempDirectory'." "Failed to change directory to working directory '$tempDirectory'."
echo "$choicesXML" > "$tempDirectory/choices.xml"
logmessage "Created choices.xml file in '$tempDirectory'." "Created choices.xml file in '$tempDirectory'."
/usr/sbin/installer -pkg "/Library/Application Support/JAMF/Waiting Room/$installerPackage" -applyChoiceChangesXML "$tempDirectory/choices.xml" -target /
logmessage "Installed TeamViewerHost package with choices." "Failed to install TeamViewerHost package with choices."
cleanup
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment