1

I want Automator script to remove files from Trash without user input. AppleScript

empty the trash

only works on unstuck files. Similar commands work in Terminal to remove files.

sudo rm -rf ~/.Trash

Still, copies of 'stuck' files are left in Trash. For example, files get stuck during move to Trash, leaving files halfway to Trash but stuck in between, so zero-byte files stuck in Trash... Terminal command will unlink Trash contents so that Trash will empty, including the zero-bytes junk.

sudo rm -rf ~/.Trash /Volumes/*/.Trashes

But Terminal has to be opened separately, then requires a user password and then manual drag and drop, blocking automation... How to automate everything?

Here's what we generally do now and need to replace with script:

  1. Check if any files in Trash
  2. If files in trash, then empty
  3. Check if any files in trash
  4. If files still in Trash, then open Terminal
  5. Run Terminal command sudo rm -rf -i -dPRrvW to break file permissions blocking delete
  6. Enter password to allow permissions change
  7. drag and drop stuck Trash files onto Terminal window
  8. Delete Trash files
  9. Check if any files in Trash
  10. If no file in Trash, then end script run

macOS Automation | AppleScript: Resources

0

I am not sure what is Trash-to-Terminal drag... but did you try the Applescript?

tell application "Finder"
 empty the trash
end tell
  • Leszek, that script is not really helpful, since "EMPTY" button is right there when you click on Trash icon. Please read topic. – mark stewart Feb 24 '17 at 11:08
  • Yes, you're right. It isn't an answer for your question. But I am guessing these scripts should help you build an automator workflow: link – Leszek Niedziela Feb 28 '17 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.