Skip to content

Instantly share code, notes, and snippets.

@thomaswitt
Last active December 7, 2023 08:13
Show Gist options
  • Save thomaswitt/c5efaa6635356edfa0b204f05b260893 to your computer and use it in GitHub Desktop.
Save thomaswitt/c5efaa6635356edfa0b204f05b260893 to your computer and use it in GitHub Desktop.
How to monitor and remove unwanted Launch Agents and Daemons in macOS (for .bash_profile)
# Remove unwanted helpers
process_agents() {
local directory=$1
shift
local agents=("$@")
local pattern=$(IFS=\|; echo "${agents[*]}")
shopt -s nullglob
for plist in "$directory"/{LaunchAgents,LaunchDaemons,PrivilegedHelperTools}/*; do
if ! echo "$plist" | egrep -q "$pattern"; then
if [[ $directory = /Library* ]]; then
echo "sudo launchctl unload -w \"$plist\""
echo -e "sudo rm -f \"$plist\"\n"
else
echo "launchctl unload -w \"$plist\""
echo -e "rm -f \"$plist\"\n"
fi
fi
done
}
global_agents=(
at.obdev.littlesnitch # Little Snitch
com.docker # Docker
com.haystacksoftware # ARQ Backup
)
process_agents "/Library" "${global_agents[@]}"
local_agents=(
com.DigiDNA.iMazing # iMazing Backup
com.docker # Docker
)
process_agents "$HOME/Library" "${local_agents[@]}"
alias show_background_tasks='sudo sfltool dumpbtm|egrep "^\W+(#\d+|Disposition:|Identifier:)"|cut -c -80'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment