Posted on
01-23-2019
05:22 PM
- last edited
Tuesday
by
kh-richa_mig
Hello Nation,
Im new to scripting and need help find the right path to "lookup" an app on the computer and if found to delete it. If the app is not installed to just echo back with a " app not found"
Does someone here have an idea?
Thanks!
Marc
Posted on 01-23-2019 06:32 PM
You can skip the scripting all together and just add the app to your restricted software in the JSS.
EX: Goole Chrome or Google Chrome.app.
Posted on 01-23-2019 07:09 PM
@mmartinez We use the following, inspired by @talkingmoose, as part of our Self Service "Remove {App}" polices:
#!/bin/sh
####################################################################################################
#
# ABOUT
#
# Removes application passed as Parameter 5. (Used prior to installing updated application.)
#
# See: https://github.com/talkingmoose/Jamf-Management-Templates/wiki/Baseline-Mozilla-Firefox
#
####################################################################################################
#
# HISTORY
#
# Version 1.0, 26-Oct-2017, Dan K. Snelson
#
####################################################################################################
# Variables
authorizationKey="$4"
applicationPath="$5"
# Check for a specified value in Parameter 4
if [[ "$authorizationKey" != "j4fUE61hjOBijRZ9GeNNyT" ]]; then
echo "Error: Incorrect Authorization Key; exiting."
exit 1
fi
# If Parameter 5 is blank, exit ...
if [[ -z "${applicationPath}" ]]; then
echo "Application Path not specified; exiting."
exit 1
fi
# Check if the specified application is installed ...
testDirectory="/Applications/${applicationPath}"
if [ -d "${testDirectory}" ] ; then
echo "/Applications/${applicationPath} located; proceeding ..."
echo "Removing /Applications/${applicationPath} ..."
/bin/rm -Rf "/Applications/${applicationPath}"
echo "Removed /Applications/${applicationPath}."
exit 0
else
echo "/Applications/${applicationPath} NOT found; nothing to remove."
exit 0
fi
exit 0
Posted on 01-24-2019 04:38 AM
@dan-snelson: I wonder what is the reason for checking the authorizationKey? The script should be triggeredand sent from a policy, so it's coming from an authenticated MDM, so what is the benefit of the authorizationKey?
The check whether parameter 5 has a value is indeed very important, removing all of /Applications is certainly not appreciated by the user ;)
I usually also try to clean /Library and remove receipts in case they exist. 'Suspicious Package' is an excellent tool to show where a package puts stuff.
Posted on 01-24-2019 08:25 AM
@mschroder My apologies, I neglected to include a reference to Authorization Key for scripts executed via Casper Remote.