Skip to main content

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

 

 

Hello! Tried this script and it works great except one thing :) Its seems to not understans app name with a "." in the name. For example zoom.us

Is there a way to fix this? :)


Hi, My script is specifically looking for apps with the extension ".app". It's not that can't find anything with "." in the name. The ".us" extension will be the issue for you.

 

I've modified it so it should now find everything in the "/Applications/" directory except apps with the "com.apple.*" bundle identifier. You may have to update your exclude list depending on what it returns. 

 

#!/bin/bash # List of apps to exculde from being able to uninstall excludeAppList=".Trash Google Chrome.app Citrix Workspace.app OneDrive.app Self Service.app Jamf* Microsoft*" # Build App list appList=$(mdfind -onlyin /Applications "kMDItemCFBundleIdentifier != com.apple.* | grep -v "$excludeAppList" | awk -F'/' '{print $NF}' | cut -f 1 -d '.' | sort -f) # Jamf helper jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" ########Functions########### uninstallSuccessful(){ description1="The $chosenApp application has been successfully uninstalled." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Application Uninstalled" -description "${description1}" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ErasingIcon.icns" -button1 "OK") } invalidEntry(){ invalidEntry="You either cancelled or the selection you made was invalid. If the application you'd like to remove is not listed, please reach out to your IT Support Team for further assistance." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Invalid Entry" -description "$invalidEntry" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDeleteIcon.icns" -button1 "OK") } listEmpty(){ listEmpty="No applications were found or all installed applications are required on your computer." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "No Applications Found" -description "$listEmpty" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns" -button1 "OK") } initializeUninstaller(){ # Force Quit the app pgrep $1 | xargs kill -15 # Remove the App /bin/rm -Rf "/Applications/$1.*" # Force Quit the app again (for redundancy) pgrep $1 | xargs kill -15 # Update JAMF Inventory sudo jamf recon } ########End of Functions########### #######Begin Main Routine########## # If list is emtpy, prompt user and exit if [ -z "${appList}" ]; then echo "No apps available for removal" listEmpty echo "App list returned as empty. Exiting..." exit 0 # If list is not empty, show list for user selection. else echo "Apps are available for removal. Prompting user with app list..." uninstallApp="choose from list every paragraph of \\"$appList\\" with title \\"Application Remover\\" with prompt \\"Select which application you'd like to uninstall: Please note: Applications that are required to be on your computer will not be listed. \\" multiple selections allowed false empty selection allowed false" chosenApp=$( /usr/bin/osascript -e "$uninstallApp" ) # If selected app exists, uninstall, prompt user and exit. if [[ -d "/Applications/$chosenApp.*" ]]; then echo "User selected $chosenApp" echo "Initializing Software Uninstaller..." initializeUninstaller "$chosenApp" # pass the app name to the function uninstallSuccessful echo "$chosenApp uninstalled" exit 0 # If user cancelled or selection was invalid, prompt user and exit. else echo "Invalid Entry" invalidEntry echo "User cancelled or made an invalid selection" exit 0 fi fi

 

 


Hi, My script is specifically looking for apps with the extension ".app". It's not that can't find anything with "." in the name. The ".us" extension will be the issue for you.

 

I've modified it so it should now find everything in the "/Applications/" directory except apps with the "com.apple.*" bundle identifier. You may have to update your exclude list depending on what it returns. 

 

#!/bin/bash # List of apps to exculde from being able to uninstall excludeAppList=".Trash Google Chrome.app Citrix Workspace.app OneDrive.app Self Service.app Jamf* Microsoft*" # Build App list appList=$(mdfind -onlyin /Applications "kMDItemCFBundleIdentifier != com.apple.* | grep -v "$excludeAppList" | awk -F'/' '{print $NF}' | cut -f 1 -d '.' | sort -f) # Jamf helper jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" ########Functions########### uninstallSuccessful(){ description1="The $chosenApp application has been successfully uninstalled." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Application Uninstalled" -description "${description1}" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ErasingIcon.icns" -button1 "OK") } invalidEntry(){ invalidEntry="You either cancelled or the selection you made was invalid. If the application you'd like to remove is not listed, please reach out to your IT Support Team for further assistance." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Invalid Entry" -description "$invalidEntry" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDeleteIcon.icns" -button1 "OK") } listEmpty(){ listEmpty="No applications were found or all installed applications are required on your computer." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "No Applications Found" -description "$listEmpty" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns" -button1 "OK") } initializeUninstaller(){ # Force Quit the app pgrep $1 | xargs kill -15 # Remove the App /bin/rm -Rf "/Applications/$1.*" # Force Quit the app again (for redundancy) pgrep $1 | xargs kill -15 # Update JAMF Inventory sudo jamf recon } ########End of Functions########### #######Begin Main Routine########## # If list is emtpy, prompt user and exit if [ -z "${appList}" ]; then echo "No apps available for removal" listEmpty echo "App list returned as empty. Exiting..." exit 0 # If list is not empty, show list for user selection. else echo "Apps are available for removal. Prompting user with app list..." uninstallApp="choose from list every paragraph of \\"$appList\\" with title \\"Application Remover\\" with prompt \\"Select which application you'd like to uninstall: Please note: Applications that are required to be on your computer will not be listed. \\" multiple selections allowed false empty selection allowed false" chosenApp=$( /usr/bin/osascript -e "$uninstallApp" ) # If selected app exists, uninstall, prompt user and exit. if [[ -d "/Applications/$chosenApp.*" ]]; then echo "User selected $chosenApp" echo "Initializing Software Uninstaller..." initializeUninstaller "$chosenApp" # pass the app name to the function uninstallSuccessful echo "$chosenApp uninstalled" exit 0 # If user cancelled or selection was invalid, prompt user and exit. else echo "Invalid Entry" invalidEntry echo "User cancelled or made an invalid selection" exit 0 fi fi

 

 


Thanks, I will try it out! :) 😃


Hi, My script is specifically looking for apps with the extension ".app". It's not that can't find anything with "." in the name. The ".us" extension will be the issue for you.

 

I've modified it so it should now find everything in the "/Applications/" directory except apps with the "com.apple.*" bundle identifier. You may have to update your exclude list depending on what it returns. 

 

#!/bin/bash # List of apps to exculde from being able to uninstall excludeAppList=".Trash Google Chrome.app Citrix Workspace.app OneDrive.app Self Service.app Jamf* Microsoft*" # Build App list appList=$(mdfind -onlyin /Applications "kMDItemCFBundleIdentifier != com.apple.* | grep -v "$excludeAppList" | awk -F'/' '{print $NF}' | cut -f 1 -d '.' | sort -f) # Jamf helper jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" ########Functions########### uninstallSuccessful(){ description1="The $chosenApp application has been successfully uninstalled." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Application Uninstalled" -description "${description1}" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ErasingIcon.icns" -button1 "OK") } invalidEntry(){ invalidEntry="You either cancelled or the selection you made was invalid. If the application you'd like to remove is not listed, please reach out to your IT Support Team for further assistance." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Invalid Entry" -description "$invalidEntry" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDeleteIcon.icns" -button1 "OK") } listEmpty(){ listEmpty="No applications were found or all installed applications are required on your computer." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "No Applications Found" -description "$listEmpty" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns" -button1 "OK") } initializeUninstaller(){ # Force Quit the app pgrep $1 | xargs kill -15 # Remove the App /bin/rm -Rf "/Applications/$1.*" # Force Quit the app again (for redundancy) pgrep $1 | xargs kill -15 # Update JAMF Inventory sudo jamf recon } ########End of Functions########### #######Begin Main Routine########## # If list is emtpy, prompt user and exit if [ -z "${appList}" ]; then echo "No apps available for removal" listEmpty echo "App list returned as empty. Exiting..." exit 0 # If list is not empty, show list for user selection. else echo "Apps are available for removal. Prompting user with app list..." uninstallApp="choose from list every paragraph of \\"$appList\\" with title \\"Application Remover\\" with prompt \\"Select which application you'd like to uninstall: Please note: Applications that are required to be on your computer will not be listed. \\" multiple selections allowed false empty selection allowed false" chosenApp=$( /usr/bin/osascript -e "$uninstallApp" ) # If selected app exists, uninstall, prompt user and exit. if [[ -d "/Applications/$chosenApp.*" ]]; then echo "User selected $chosenApp" echo "Initializing Software Uninstaller..." initializeUninstaller "$chosenApp" # pass the app name to the function uninstallSuccessful echo "$chosenApp uninstalled" exit 0 # If user cancelled or selection was invalid, prompt user and exit. else echo "Invalid Entry" invalidEntry echo "User cancelled or made an invalid selection" exit 0 fi fi

 

 


The problem was the Zoom app was called zoom.us.app and it did not show up :( I tried the new script but it throws an error lite this. Any ideas? :)

 

Script result: /Library/Application Support/JAMF/tmp/RV Universal uninstaller: line 87: unexpected EOF while looking for matching `"'
/Library/Application Support/JAMF/tmp/RV Universal uninstaller: line 93: syntax error: unexpected end of file


Hi, My script is specifically looking for apps with the extension ".app". It's not that can't find anything with "." in the name. The ".us" extension will be the issue for you.

 

I've modified it so it should now find everything in the "/Applications/" directory except apps with the "com.apple.*" bundle identifier. You may have to update your exclude list depending on what it returns. 

 

#!/bin/bash # List of apps to exculde from being able to uninstall excludeAppList=".Trash Google Chrome.app Citrix Workspace.app OneDrive.app Self Service.app Jamf* Microsoft*" # Build App list appList=$(mdfind -onlyin /Applications "kMDItemCFBundleIdentifier != com.apple.* | grep -v "$excludeAppList" | awk -F'/' '{print $NF}' | cut -f 1 -d '.' | sort -f) # Jamf helper jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" ########Functions########### uninstallSuccessful(){ description1="The $chosenApp application has been successfully uninstalled." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Application Uninstalled" -description "${description1}" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ErasingIcon.icns" -button1 "OK") } invalidEntry(){ invalidEntry="You either cancelled or the selection you made was invalid. If the application you'd like to remove is not listed, please reach out to your IT Support Team for further assistance." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Invalid Entry" -description "$invalidEntry" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDeleteIcon.icns" -button1 "OK") } listEmpty(){ listEmpty="No applications were found or all installed applications are required on your computer." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "No Applications Found" -description "$listEmpty" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns" -button1 "OK") } initializeUninstaller(){ # Force Quit the app pgrep $1 | xargs kill -15 # Remove the App /bin/rm -Rf "/Applications/$1.*" # Force Quit the app again (for redundancy) pgrep $1 | xargs kill -15 # Update JAMF Inventory sudo jamf recon } ########End of Functions########### #######Begin Main Routine########## # If list is emtpy, prompt user and exit if [ -z "${appList}" ]; then echo "No apps available for removal" listEmpty echo "App list returned as empty. Exiting..." exit 0 # If list is not empty, show list for user selection. else echo "Apps are available for removal. Prompting user with app list..." uninstallApp="choose from list every paragraph of \\"$appList\\" with title \\"Application Remover\\" with prompt \\"Select which application you'd like to uninstall: Please note: Applications that are required to be on your computer will not be listed. \\" multiple selections allowed false empty selection allowed false" chosenApp=$( /usr/bin/osascript -e "$uninstallApp" ) # If selected app exists, uninstall, prompt user and exit. if [[ -d "/Applications/$chosenApp.*" ]]; then echo "User selected $chosenApp" echo "Initializing Software Uninstaller..." initializeUninstaller "$chosenApp" # pass the app name to the function uninstallSuccessful echo "$chosenApp uninstalled" exit 0 # If user cancelled or selection was invalid, prompt user and exit. else echo "Invalid Entry" invalidEntry echo "User cancelled or made an invalid selection" exit 0 fi fi

 

 


Did it work for you? I get an error with the new script :S


Did it work for you? I get an error with the new script :S


Sorry for the late response. You might have figured it out already, but I left out a quotation that was producing a syntax error and yes, "zoom.us.app" was messing it up as it contains two dots. It should now extract everything before the last dot. Give it a try. 

 

#!/bin/bash # List of apps to exclude from being able to uninstall excludeAppList=".Trash Google Chrome.app Citrix Workspace.app OneDrive.app Self Service.app Jamf* Microsoft*" # Build App list appList=$(mdfind -onlyin /Applications "kMDItemCFBundleIdentifier != com.apple.*" | grep -v "$excludeAppList" | awk -F'/' '{print $NF}' | rev | cut -d '.' -f 2- | rev | sort -f) # Jamf helper jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" ######## Functions ########### uninstallSuccessful() { description1="The $chosenApp application has been successfully uninstalled." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Application Uninstalled" -description "${description1}" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ErasingIcon.icns" -button1 "OK") } invalidEntry() { invalidEntry="You either cancelled or the selection you made was invalid. If the application you'd like to remove is not listed, please reach out to your IT Support Team for further assistance." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "Invalid Entry" -description "$invalidEntry" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDeleteIcon.icns" -button1 "OK") } listEmpty() { listEmpty="No applications were found or all installed applications are required on your computer." buttonClicked=$("$jamfHelper" -windowType utility -windowPosition "center" -title "No Applications Found" -description "$listEmpty" -alignDescription "Left" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns" -button1 "OK") } initializeUninstaller() { # Force Quit the app pgrep "$1" | xargs kill -15 # Remove the App /bin/rm -Rf "/Applications/$1.app" # Force Quit the app again (for redundancy) pgrep "$1" | xargs kill -15 # Update JAMF Inventory sudo jamf recon } ######## End of Functions ########### ####### Begin Main Routine ########## # If list is empty, prompt user and exit if [ -z "${appList}" ]; then echo "No apps available for removal" listEmpty echo "App list returned as empty. Exiting..." exit 0 else echo "Apps are available for removal. Prompting user with app list..." uninstallApp="choose from list every paragraph of \\"$appList\\" with title \\"Application Remover\\" with prompt \\"Select which application you'd like to uninstall: Please note: Applications that are required to be on your computer will not be listed. \\" multiple selections allowed false empty selection allowed false" chosenApp=$( /usr/bin/osascript -e "$uninstallApp" ) # If selected app exists, uninstall, prompt user and exit. if [[ -d "/Applications/$chosenApp.app" ]]; then echo "User selected $chosenApp" echo "Initializing Software Uninstaller..." initializeUninstaller "$chosenApp" # pass the app name to the function uninstallSuccessful echo "$chosenApp uninstalled" exit 0 else echo "Invalid Entry" invalidEntry echo "User cancelled or made an invalid selection" exit 0 fi fi