Skip to main content

Trying to create a script (python or bash) to push out in a policy via Jamf Pro to delete Google Chrome.app from a system. I've tried various scripts online (new to scripting sorry) and everything fails. I'm currently testing this script and trying to run it manually using bash chrome-uninstall.sh but it keeps saying command not found. What am I doing wrong?



#!/bin/bash

# Remove Chrome
rm -rf /Applications/Google Chrome.app/

exit 0

How about this?




Hi,



You can upload script below into Jamf Pro to use within policies and using Parameter 4 to set the application name or using Jamf Remote to remove an application.



#!/bin/bash

# This script can delete apps that are sandboxed and live in /Applications
# The first parameter is used to kill the app. It should be the app name or path
# as required by the pkill command.
applicationPath="$4"

if [[ -z "${applicationPath}" ]]; then
echo "No application specified!"
exit 1
fi

## Closing Application
echo "Closing application: ${applicationPath}"
pkill "${applicationPath}"

## Removing Application
echo "Removing application: ${applicationPath}"
rm -rf "/Applications/${applicationPath}.app"

exit 0





Worked perfect, thank you!


Thank you @txhaflaire, this is really helpful. I haven't revisited this for some time. I had other ways to accomplish this. This is certainly simpler and can be reused for a few things I am sure. Thank you.


@txhaflaire Thanks for the script. Really good. Is there a way we can also remove the plist file along with the application ?



Thanks


@ayotec Which plist do you mean ? can you provide location? thanks!


@ayotec Else something should work;



#!/bin/bash

# This script can delete apps that are sandboxed and live in /Applications
# The first parameter is used to kill the app. It should be the app name or path
# as required by the pkill command.
# the second parameter is used for removing a preference file / any file if specified.
applicationPath="$4"
plistPath="$5"

if [[ -z "${applicationPath}" ]]; then
echo "No application specified!"
exit 1
fi

## Closing Application
echo "Closing application: ${applicationPath}"
pkill "${applicationPath}"

## Removing Application
while [ -d /Applications/${applicationPath}.app ];
do
echo "${applicationPath} does exist, going to remove it."
rm -rf "/Applications/${applicationPath}.app"
sleep 1;
done;
echo "${applicationPath} does not exist, nothing to remove"
sleep 1;

## Removing preference file if specified
if [ -f "${plistPath}" ]; then
echo "${plistPath} found.. removing"
rm -f "${plistPath}"
fi

exit 0



Thank you @ThijsX ! This is going to save me a lot of time!


Reply