Skip to content

Instantly share code, notes, and snippets.

@ph00lt0
Last active February 14, 2022 16:02
Show Gist options
  • Save ph00lt0/4ad1ecb8b3adda794a52166a54aa23fd to your computer and use it in GitHub Desktop.
Save ph00lt0/4ad1ecb8b3adda794a52166a54aa23fd to your computer and use it in GitHub Desktop.
#! /bin/bash
# Origin: https://github.com/sunknudsen/privacy-guides/tree/master/how-to-clean-uninstall-macos-apps-using-appcleaner-open-source-alternative
if [ -z "$1" ] || [ "$1" = "--help" ]; then
printf "%s\n" "Usage: app-cleaner.sh /path/to/app.app"
exit 0
fi
IFS=$'\n'
red=$(tput setaf 1)
normal=$(tput sgr0)
if [ ! -e "$1/Contents/Info.plist" ]; then
printf "%s\n" "Cannot find app plist"
exit 1
fi
bundle_identifier=$(/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "$1/Contents/Info.plist" 2> /dev/null)
if [ "$bundle_identifier" = "" ]; then
printf "%s\n" "Cannot find app bundle identifier"
exit 1
fi
printf "%s\n" "Checking for running processes…"
sleep 1
app_name=$(basename $1 .app)
processes=($(pgrep -afil "$app_name" | grep -v "app-cleaner.sh"))
if [ ${#processes[@]} -gt 0 ]; then
printf "%s\n" "${processes[@]}"
printf "$red%s$normal" "Kill running processes (y or n)? "
read -r answer
if [ "$answer" = "y" ]; then
printf "%s\n" "Killing running processes…"
sleep 1
for process in "${processes[@]}"; do
echo $process | awk '{print $1}' | xargs sudo kill 2>&1 | grep -v "No such process"
done
fi
fi
paths=()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment