Skip to content

Instantly share code, notes, and snippets.

@cam8001
Created August 30, 2025 23:51
Show Gist options
  • Save cam8001/e144e04d7d847c6a738076eaec492cb5 to your computer and use it in GitHub Desktop.
Save cam8001/e144e04d7d847c6a738076eaec492cb5 to your computer and use it in GitHub Desktop.
Force close a bunch of apps on a mac in an ugly way
#!/usr/bin/env zsh
# Brute force kill a bunch of apps when you have let your Mac get a bit carried away.
# Source this from your ~/.zshrc, then run `cleanup_running_procs`
# e.g., save this to ~/bin/close-programs.sh, then in your ~/.zshrc
# source ~/bin/close-programs.sh
# List out some apps in a file at ~/bin/killable.txt you want to close.
# List is case insensitive and is based on a grep match (so can just be part
# of a name, eg 'word' for 'Microsoft Word')
KILLABLE_APPS_LIST_FILE=`realpath ~/bin/killable.txt`
# List the full path to each running proc on this system
get_running_procs() {
ps -ef | awk '{for(i=8;i<=NF;i++) printf "%s%s", $i, (i==NF?"\n":" ")}'
}
# To filter down to just app names:
# You could use this to generate a list of killables to put in killables.txt
# get_running_procs | egrep -o '[^/]+\.app'
# Iterate through each line in killable.txt
cleanup_running_procs() {
while IFS= read -r line; do
# formatting below for bold with red background
echo "Attempting to kill processes with case-insensitive \033[1;41m\"$line\"\033[0m in the name..."
kill $(ps -ef | grep -i $line | grep -v grep | awk '{print $2}')
#echo "$line"
done < $KILLABLE_APPS_LIST_FILE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment