Created
May 8, 2025 12:45
-
-
Save nanotaboada/a60dc532e431f0033f461de77910b0c3 to your computer and use it in GitHub Desktop.
π Finds and safely deletes app leftovers in common macOS Library folders
This file contains hidden or 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 | |
# ------------------------------------------------------------------------------ | |
# π Finds and safely deletes app leftovers in common macOS Library folders | |
# | |
# This script searches macOS user and system Library directories for files or | |
# folders that match a given keyword (e.g., "Lorem", "Lorem Ipsum"). | |
# It helps identify residual files from previously installed apps that may | |
# continue running in the background or occupy disk space. | |
# | |
# It supports interactive deletion with confirmation prompts for each match, | |
# and handles both files and directories. | |
# | |
# Features: | |
# - Searches safe-to-modify paths: ~/Library, /Library/LaunchAgents, etc. | |
# - Excludes SIP-protected paths like /System/Library | |
# - Handles directories using `rm -rv` | |
# - Automatically escalates privileges (sudo) for /Library paths | |
# - Pretty colored output and emojis for clarity | |
# | |
# Usage: | |
# ./find-in-library.sh "Keyword" | |
# ------------------------------------------------------------------------------ | |
# Color setup | |
GREEN="\033[0;32m" | |
RED="\033[0;31m" | |
YELLOW="\033[1;33m" | |
BLUE="\033[0;34m" | |
NC="\033[0m" # No Color | |
# Check for search term | |
if [ -z "$1" ]; then | |
echo -e "${RED}β Please provide a search term.${NC}" | |
echo -e "π Usage: ${YELLOW}$0 \"Your Keyword\"${NC}" | |
exit 1 | |
fi | |
KEYWORD="$1" | |
echo -e "${BLUE}π Searching for: ${YELLOW}${KEYWORD}${NC}" | |
# Search paths (excluding SIP-protected ones) | |
SEARCH_DIRS=( | |
"$HOME/Library" | |
"$HOME/Library/LaunchAgents" | |
"/Library/LaunchAgents" | |
"/Library/LaunchDaemons" | |
) | |
FOUND=false | |
for DIR in "${SEARCH_DIRS[@]}"; do | |
if [ -d "$DIR" ]; then | |
echo -e "${BLUE}π Searching in: ${DIR}${NC}" | |
RESULTS=$(find "$DIR" -iname "*$KEYWORD*" 2>/dev/null) | |
if [ -n "$RESULTS" ]; then | |
echo -e "${GREEN}β Matches found:${NC}" | |
echo "$RESULTS" | |
IFS=$'\n' | |
for FILE in $RESULTS; do | |
echo -en "${YELLOW}ποΈ Delete?${NC} ${FILE} [y/N]: " | |
read -r CONFIRM | |
if [[ "$CONFIRM" =~ ^[Yy]$ ]]; then | |
if [ -d "$FILE" ]; then | |
echo -e "${BLUE}π Removing directory...${NC}" | |
rm -rv "$FILE" | |
else | |
if [[ "$FILE" == /Library/* ]]; then | |
sudo rm -v "$FILE" | |
else | |
rm -v "$FILE" | |
fi | |
fi | |
else | |
echo -e "${BLUE}β‘οΈ Skipped.${NC}" | |
fi | |
done | |
FOUND=true | |
else | |
echo -e "${YELLOW}β οΈ No matches found in this location.${NC}" | |
fi | |
fi | |
done | |
if [ "$FOUND" = false ]; then | |
echo -e "${RED}π« No matches found anywhere for '${KEYWORD}'.${NC}" | |
else | |
echo -e "${GREEN}π Done! All matching files processed.${NC}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment