Universal Application Uninstall Script

MPL
Contributor II

Hello Jamf Community,

 

Not sure whether this has been done or not but I'm looking to see if anyone has any ideas/scripts for creating a sort of universal uninstaller for approved applications. 

All of our users are standard users and we only want them to uninstall certain applications we deem "approved" for uninstallation. As such, we are looking for something that creates a pop-up window which allow them to select from a predefined list of apps to uninstall.

 

Is anyone aware of something like this that exists? Or have an idea on how to create it? I'm not the best at scripting...

7 REPLIES 7

talkingmoose
Moderator
Moderator

I created this a while back as part of some app lifecycle management I was doing back then. Always been amused it's 98% comment and 2% script.

Stupid simple for creating a single policy per app. You may be able to modify it for your needs.

https://gist.github.com/talkingmoose/08c279ab87250299ab602bf44493da91

sgiesbrecht
Contributor III

I use these scripts 
[App] Force Quit.sh to quit app first then [Uninstall] Application.sh to remove.   For apps, I add the .app in Parameter 4 (e.g. Safari.app) and for folders I just enter the folder name (Adobe Connect).  Simple but gets the job done

#! /bin/bash

# Force Quit the app
ps aux | grep "$4" | grep -v "grep" | awk '{print $2}' | xargs kill -15
#! /bin/bash
# Uninstall App
rm -rf "/Applications/$4"

 

@sgiesbrecht @talkingmoose 

 

These are both great to start.

 

I'm looking for some sort of jamfhelper (maybe?) or applescript option where I can have a window come up with buttons/a drop down of certain applications that can be selected for uninstallation. Once selected, the script would run and uninstall the selected app.

 

For instance, selection 1 would be Adobe, selection 2 would be Firefox, selection 3 would be Safari, etc. 

 

Is there any way to do that? 

sgiesbrecht
Contributor III

for most apps, uninstall is just deleting the .app folder.
for apps that have an uninstall command, you will have to follow their steps  or launch their scripts
Currently we use Jamf Policy to uninstall apps

you can use this https://github.com/BIG-RAT/jhc as the JamfHelper as it has pull-down options for times but you may be able to tweak it to do commands instead

 

 

Heya,

So i'm specifically trying to create a policy for users to be able to run (note that all users in my org are standard, not admins) so that they can be presented with a selection of Apps to choose from for uninstallation.

 

So as an example, once the policy is run, a popup window would appear with a list of apps to choose from for the user to uninstall.

 

Is there a way to do that with jamfhelper or applescript?

talkingmoose
Moderator
Moderator

I have a snippet that may help you. Jamf Helper has no ability to let you customize its drop down menu the way you'd like, but AppleScript does support a choose from list command.

#!/bin/zsh

rolesList="Cart
Computer Labs
GradID
Library
Photo Lab
Staff"

theCommand="choose from list every paragraph of \"$rolesList\" with title \"Choose Computer Role\" with prompt \"Select the computer role for this Mac...\" multiple selections allowed false empty selection allowed false"

computerRole=$( /usr/bin/osascript -e "$theCommand" )

exit

But, is a script like this really worth the time? How often will an end user really need to uninstall multiple applications at once? Don't forget, they can click on several Self Service items, one after the other, and they'll queue up. One doesn't have to finish before clicking the next.

Hey talkingmooose! Thanks for providing that. I feel like I am close to being done with my script but still have a few errors.

I'm going to post my full code below so you can kind of get an idea of what I am trying to do. Ultimately, I just want to write a script with parameters so that we can add "approved" apps for uninstallation for our users if that makes sense. Otherwise, we have to give our users temporary admin to uninstall apps themselves.

 

 

 

 

#!/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

 

 

 

As far as Self Service, is there a built-in uninstall option? I've tried to locate one with no success.