Skip to main content
Jamf Nation, hosted by Jamf, is a knowledgeable community of Apple-focused admins and Jamf users. Join us in person at the ninth annual Jamf Nation User Conference (JNUC) this November for three days of learning, laughter and IT love.

Script to check for app and delete

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

Like Comment
Order by:
SOLVED Posted: by jgsims

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.

Like
SOLVED Posted: by dan-snelson

@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
Like
SOLVED Posted: by mschroder

@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.

Like
SOLVED Posted: by dan-snelson

@mschroder My apologies, I neglected to include a reference to Authorization Key for scripts executed via Casper Remote.

Like

Jamf wants to hear your feedback around Peripherals and Jamf Connect settings configuration