Last active
February 14, 2022 16:02
-
-
Save ph00lt0/4ad1ecb8b3adda794a52166a54aa23fd to your computer and use it in GitHub Desktop.
App clearer, origin: https://github.com/sunknudsen/privacy-guides/tree/master/how-to-clean-uninstall-macos-apps-using-appcleaner-open-source-alternative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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