Force emptying the trash on macOS by calling shell script

I also tried the rm -rf ~/.Trash/* command, with the below result.

Last login: Thu Mar 20 10:15:41 on ttys000
margehomer@MargeHomers-Mac-mini ~ % rm -rf ~/.Trash/*
zsh: sure you want to delete all the files in /Users/margehomer/.Trash [yn]? y
zsh: no matches found: /Users/margehomer/.Trash/*
margehomer@MargeHomers-Mac-mini ~ %

I’m running Sonoma 14.7.4

I’ve Googled “applescript to force empty trash” for hours, with little to show for it.

I did find something that works but it dates back to 2007 here on MacScripter, post #4 by StephanK, Empty the trash (again) - #3 by John_Love

activate application "Finder"
tell application "System Events" to tell process "Finder"
	key code 51 using {option down, shift down, command down}
end tell

Homer712. I’m running Sequoia and you’re running Sonoma, and this could easily make a difference. FWIW, I ran the above shell command, and it completed without error and emptied the trash.

I then disabled Terminal’s Full Disk Access permission.

I then got the same result as you and the trash was not emptied.

I can’t tell you haw many times I’ve run into this issue . . . and still can’t remember to first check Full Disk Access. Checked, reset the Terminal (I think it may get “unset” during MacOS updates), but can’t be sure.

In any event, the “rm -rf ~/.Trash/*” is now working perfectly here as well.

Since macOS 12, “moving to trash” has some special meaning in certain cases—like when you move an app to the trash, it also gets removed from the Dock.

Because of that, I’ve made it a habit to move things to the trash first before deleting them.

I was mainly cleaning up unused application data by moving files under

$HOME/Library/Containers/com.some.app to the trash.

Since sandboxed application preference folders often contain a lot of symbolic links, I made the mistake of using rm -rf… and, well, it didn’t end well for me. Sigh… :sweat_smile:

Since then, I’ve developed a bit of an rm -rf phobia… lol.