3

Is there any way I can create an automator service or app to delete ALL trash from any USB drive (my own account's trash plus everybody else's)?

I've read several solutions involving Terminal, including this one, but I'd like something a bit more foolproof and really handy.

I need to exchange USB drives regularly for presentations at events and Mac trash is becoming a problem as Macs become more common -- people suddenly get "no space available" error messages and can't do anything about it. I know how to skip the trash, but need a quick fix when the trash is already there.

2 Answers2

2

2 Solutions. 1 using Bash the other using Bash wrapped in AppleScript.

Solution #1

  1. Create a new AppleScript with /Applications/Utilities/AppleScript Editor
  2. Type the following code:

    do shell script "rm -rf /Volumes/*/.Trashes/*" with administrator privileges
    
  3. Save the file to somewhere convenient and run it whenever you need to clear the USB Trash
  4. This can be executed by double-clicking on it

NOTE: This will empty the Trash for all connected volumes including your internal hard disk. If you have connected 5 USB drives and a Firewire hard disk, it will empty the trash for all of them.


Solution #2

  1. Fire up your favourite text editor (mine is nano)
  2. Paste the following code into your text editor and save the file

    #!/bin/bash  
    sudo rm -rf /Volumes/*/.Trashes/*
    
  3. Save the file to somewhere convenient with the extension .sh and then make it executable with chmod +x {filename}.sh from Terminal
  4. Run that with ./{filename}.sh

NOTE: Same note as above. This is executable from Terminal.

0

Using Automator :

  • Create a new Service with automator
  • Change Service receives selected to files and folders
  • Change pass input to “as arguments” from “stdin”
  • Add a Run ShellScript action

Use this script

find /Volumes/ -maxdepth 2 -mindepth 2 | grep .Trashes | xargs rm -R
  • Save your new service

It will be accessible from the right clic under the name you saved it.

Matthieu Riegler
  • 21,486
  • 11
  • 59
  • 97