Hello Jamf Community,
I previously posted this a couple weeks ago but still am struggling to figure out exactly how to get it working.
I am trying to create a script that will prompt a user with a popup box on which application they'd like to uninstall (only apps we deem approved). For example, a popup would come up and ask someone "Select an app you'd like to uninstall" with a list of apps such as, Google Chrome, Firefox, Adobe, etc.
Currently I have script that I feel is about 90% of the way there but still can't figure out how to get it completely working. I'll post it below.
Also, if there's any easier way to do this, please do let me know as well!
Any help is greatly appreciated! There may be some unnecessary lines in the script just FYI. Here's the script:
#!/bin/bash
# Parameters
app1="$4"
app2="$5"
app3="$6"
app4="$7"
app5="$8"
appList="$4
$5
$6
$7
$8"
uninstallApp="choose from list every paragraph of \\"$appList\\" with title \\"Application Uninstaller\\" with prompt \\"Select which application you'd like to uninstall: \\" multiple selections allowed false empty selection allowed false"
chosenApp=$( /usr/bin/osascript -e "$uninstallApp" )
exit
# Jamf helper information
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
description1="Select one of the following approved applications to uninstall:"
description2="The software you selected has been uninstalled."
invalidEntry="Invalid Entry"
########Functions###########
uninstallSuccessful(){
buttonClicked=$("$jamfHelper" -windowType hud -lockHUD -windowPosition "center" -title "Software Uninstalled" -description "${description2}" -alignDescription "Left" -button1 "OK")
}
invalidEntry(){
buttonClicked=$("$jamfHelper" -windowType hud -lockHUD -windowPosition "center" -title "Invalid Entry" -description "$invalidEntry" -alignDescription "Left" -button1 "OK")
}
initializeUninstaller1(){
# Force Quit the app
ps aux | grep "$4.app" | grep -v "grep" | awk '{print $2}' | xargs kill -15
# Remove the App
/bin/rm -Rf "/Applications/$4.app"
}
initializeUninstaller2(){
# Force Quit the app
ps aux | grep "$5.app" | grep -v "grep" | awk '{print $2}' | xargs kill -15
# Remove the App
/bin/rm -Rf "/Applications/$5.app"
}
initializeUninstaller3(){
# Force Quit the app
ps aux | grep "$6.app" | grep -v "grep" | awk '{print $2}' | xargs kill -15
# Remove the App
/bin/rm -Rf "/Applications/$6.app"
}
appCheck(){
if [[ $chosenApp == $4 ]]; then
echo "User selected $4"
echo "Initializing Software Uninstaller"
initializeUninstaller1
uninstallSuccessful
elif [[ $chosenApp == $5 ]]; then
echo "User selected $5"
echo "Initializing Software Uninstaller"
initializeUninstaller2
uninstallSuccessful
elif [[ $chosenApp == $6 ]]; then
echo "User selected $6"
echo "Initializing Software Uninstaller"
initializeUninstaller3
uninstallSuccessful
elif [[ $chosenApp != "2745wnfeljf23490" ]]; then
echo "Invalid Entry"
invalidEntry
exit 0
fi
}
appCheck
exit 0 ## Success
exit 1 ## Failure