From 02b729d5dc168040185e8757043ae989101c9dd7 Mon Sep 17 00:00:00 2001 From: Mario Panighetti Date: Thu, 25 Sep 2025 15:25:36 -0700 Subject: [PATCH 1/2] moved script parameters after environment variables - moved script parameters after environment variables (allows referencing variables like $loggedInUserHome in Jamf Pro policy parameters) --- .../Uninstall Single Application.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh b/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh index cb73eb1..6f03522 100755 --- a/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh +++ b/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh @@ -6,8 +6,8 @@ # Description: A template script to assist with the uninstallation of macOS products where the vendor has missing or incomplete removal solutions. Attempts vendor uninstall by running all provided uninstallation executables, quits all running target processes, then removes all associated target files. # https://github.com/palantir/jamf-pro-scripts/tree/main/scripts/script-templates/uninstaller-template # Created: 2017-10-23 -# Last Modified: 2023-07-24 -# Version: 2.0pal1 +# Last Modified: 2025-09-25 +# Version: 2.0pal2 # # # Copyright 2017 Palantir Technologies, Inc. @@ -33,13 +33,6 @@ -# Jamf Pro script parameter: "App Process" -appProcess="${4}" -# Jamf Pro script parameter: "App File Path" -# Should be full path to the application, e.g. "/System/Applications/Chess.app" -appFilePath="${5}" - - loggedInUser=$(/usr/bin/stat -f%Su "/dev/console") loggedInUserUID=$(/usr/bin/id -u "$loggedInUser") # For any file paths used later in this script, use "$loggedInUserHome" for the current user's home folder path. Don't just assume the home folder is at /Users/${loggedInUser}. @@ -47,6 +40,13 @@ loggedInUserUID=$(/usr/bin/id -u "$loggedInUser") loggedInUserHome=$(/usr/bin/dscl . -read "/Users/${loggedInUser}" NFSHomeDirectory | /usr/bin/awk '{print $NF}') +# Jamf Pro script parameter: "App Process" +appProcess="${4}" +# Jamf Pro script parameter: "App File Path" +# Should be full path to the application, e.g. "/System/Applications/Chess.app" +appFilePath="${5}" + + ########## function-ing ########## From df97afb5d68a6d5fecf5b00ce25fb5d9c7714a68 Mon Sep 17 00:00:00 2001 From: Mario Panighetti Date: Thu, 25 Sep 2025 16:04:46 -0700 Subject: [PATCH 2/2] added string replacement function added convert_path_to_home() function for string replacement (takes `LOGGED_IN_USER_HOME/` and replaces with `$loggedInUserHome/` defined earlier in script) --- .../Uninstall Single Application.sh | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh b/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh index 6f03522..89ca69c 100755 --- a/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh +++ b/scripts/script-templates/uninstaller-template/Uninstall Single Application.sh @@ -33,6 +33,13 @@ +# Jamf Pro script parameter: "App Process" +appProcess="${4}" +# Jamf Pro script parameter: "App File Path" +# Should be full path to the application, e.g. "/System/Applications/Chess.app". If referencing the current user's home folder path, replace "~/" with "LOGGED_IN_USER_HOME/", e.g. "LOGGED_IN_USER_HOME/Applications/Google Chrome.app". +appFilePath="${5}" + + loggedInUser=$(/usr/bin/stat -f%Su "/dev/console") loggedInUserUID=$(/usr/bin/id -u "$loggedInUser") # For any file paths used later in this script, use "$loggedInUserHome" for the current user's home folder path. Don't just assume the home folder is at /Users/${loggedInUser}. @@ -40,19 +47,12 @@ loggedInUserUID=$(/usr/bin/id -u "$loggedInUser") loggedInUserHome=$(/usr/bin/dscl . -read "/Users/${loggedInUser}" NFSHomeDirectory | /usr/bin/awk '{print $NF}') -# Jamf Pro script parameter: "App Process" -appProcess="${4}" -# Jamf Pro script parameter: "App File Path" -# Should be full path to the application, e.g. "/System/Applications/Chess.app" -appFilePath="${5}" - - ########## function-ing ########## -# Exit if any required Jamf Pro arguments are undefined. +# Exits if any required Jamf Pro arguments are undefined. check_jamf_pro_arguments () { if [ -z "$appProcess" ] || [ -z "$appFilePath" ]; then @@ -75,6 +75,17 @@ quit_process () { } +# Takes LOGGED_IN_USER_HOME placeholder and replaces with $loggedInUserHome. +convert_path_to_home () { + + if echo "$appFilePath" | /usr/bin/grep -q "LOGGED_IN_USER_HOME/"; then + appFilePath=$(echo "$appFilePath" | /usr/bin/sed "s|LOGGED_IN_USER_HOME|$loggedInUserHome|") + echo "Converted input to file path: ${appFilePath}" + fi + +} + + # Removes specified file. delete_file () { @@ -120,7 +131,8 @@ quit_process "$appProcess" # FILE PATHS -# For each file and/or folder related to the target product, run the delete_file function calling that file name. Leave off trailing slashes from directory paths. Call the function again for each additional file. If no files need to be deleted, comment out or remove this line. +# For each file and/or folder related to the target product, run the delete_file function calling that file name. Leave off trailing slashes from directory paths. Call the function again for each additional file. If no files need to be deleted, comment out or remove this line. Replaces LOGGED_IN_USER_HOME placeholder with $loggedInUsrHome as needed. +convert_path_to_home delete_file "$appFilePath"