From 89eb442866d6b9dccea1603d8e2e667cff9e2cc0 Mon Sep 17 00:00:00 2001 From: Andrei Murariu <83287213+iamxorum@users.noreply.github.com> Date: Mon, 26 Jan 2026 04:28:03 +0200 Subject: [PATCH] bug-fix: add automatic trash emptying to clean command (#363) - Empty trash using macOS Finder API (osascript) for proper permission handling - Respects whitelist protection (skips if Trash is whitelisted) - Shows item count when emptying trash - Fallback to direct cleanup if Finder API fails - Supports dry-run mode Issue: #362 --- lib/clean/user.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/clean/user.sh b/lib/clean/user.sh index baf98ab..3293841 100644 --- a/lib/clean/user.sh +++ b/lib/clean/user.sh @@ -7,8 +7,24 @@ clean_user_essentials() { stop_section_spinner safe_clean ~/Library/Logs/* "User app logs" + if ! is_path_whitelisted "$HOME/.Trash"; then - safe_clean ~/.Trash/* "Trash" + local trash_count + trash_count=$(osascript -e 'tell application "Finder" to count items in trash' 2> /dev/null || echo "0") + [[ "$trash_count" =~ ^[0-9]+$ ]] || trash_count="0" + + if [[ "${DRY_RUN:-false}" == "true" ]]; then + [[ $trash_count -gt 0 ]] && echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Trash · would empty ($trash_count items)" || echo -e " ${GRAY}${ICON_EMPTY}${NC} Trash · already empty" + elif [[ $trash_count -gt 0 ]]; then + if osascript -e 'tell application "Finder" to empty trash' > /dev/null 2>&1; then + echo -e " ${GREEN}${ICON_SUCCESS}${NC} Trash · emptied ($trash_count items)" + note_activity + else + safe_clean ~/.Trash/* "Trash" + fi + else + echo -e " ${GRAY}${ICON_EMPTY}${NC} Trash · already empty" + fi fi }