Skip to main content
Solved

App Uninstallation Script (Universal)

  • June 10, 2022
  • 30 replies
  • 213 views

Show first post

30 replies

Jay_007
Forum|alt.badge.img+7
  • Valued Contributor
  • December 18, 2023

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

 

 


Forum|alt.badge.img+4
  • Contributor
  • December 18, 2023

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! :) 😃


Forum|alt.badge.img+4
  • Contributor
  • December 20, 2023

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


Forum|alt.badge.img+4
  • Contributor
  • January 9, 2024

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


Jay_007
Forum|alt.badge.img+7
  • Valued Contributor
  • January 26, 2024

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