From 30547c9c4c6a36b0b2c217c2343d757b358b7af8 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 15 Jan 2026 15:13:51 +0800 Subject: [PATCH] refactor(uninstall): enhance login item removal and brew UI - Escape quotes/backslashes in app names for AppleScript safety - Silence osascript stdout to prevent output noise - Capture brew uninstall output to avoid spinner corruption - Log brew errors to debug_log for troubleshooting --- lib/uninstall/batch.sh | 8 ++++++-- lib/uninstall/brew.sh | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/uninstall/batch.sh b/lib/uninstall/batch.sh index 7e914ac..cf98629 100755 --- a/lib/uninstall/batch.sh +++ b/lib/uninstall/batch.sh @@ -104,7 +104,11 @@ remove_login_item() { # Remove from Login Items using index-based deletion (handles broken items) if [[ -n "$clean_name" ]]; then - osascript <<- EOF 2> /dev/null || true + # Escape double quotes and backslashes for AppleScript + local escaped_name="${clean_name//\\/\\\\}" + escaped_name="${escaped_name//\"/\\\"}" + + osascript <<- EOF > /dev/null 2>&1 || true tell application "System Events" try set itemCount to count of login items @@ -112,7 +116,7 @@ remove_login_item() { repeat with i from itemCount to 1 by -1 try set itemName to name of login item i - if itemName is "$clean_name" then + if itemName is "$escaped_name" then delete login item i end if end try diff --git a/lib/uninstall/brew.sh b/lib/uninstall/brew.sh index 1cecdbf..a749e6a 100644 --- a/lib/uninstall/brew.sh +++ b/lib/uninstall/brew.sh @@ -175,9 +175,12 @@ brew_uninstall_cask() { # Run uninstall with timeout (suppress hints/auto-update) local uninstall_ok=false - if HOMEBREW_NO_ENV_HINTS=1 HOMEBREW_NO_AUTO_UPDATE=1 NONINTERACTIVE=1 \ - run_with_timeout 120 brew uninstall --cask "$cask_name" 2>&1; then + local output + if output=$(HOMEBREW_NO_ENV_HINTS=1 HOMEBREW_NO_AUTO_UPDATE=1 NONINTERACTIVE=1 \ + run_with_timeout 120 brew uninstall --cask "$cask_name" 2>&1); then uninstall_ok=true + else + debug_log "brew uninstall output: $output" fi # Verify removal