Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

The "Empty Trash" is a bit non-specific for me, as it empties the trash on all connected volumes. In order to empty trash from a single drive (for instance, on a USB stick), I've been going to the terminal and using:

sudo rm -R /Volumes/<volume_name>/.Trashes

What I'd really like is some App/Finder Extension/Menulet/etc that would let me empty the trash without having to run to the terminal (and without having to supply a password).

I could wrap the bash command in an Applescript/Automator script, but supplying the volume name is troublesome.

Any ideas? Bonus points if I can choose to "Securely Empty Trash."

share|improve this question
1  
If you use srm instead of rm, you'll securely delete instead of regular deleting. –  CajunLuke Sep 27 '11 at 14:35
    
Honest Question: Why do you need to selectively delete volumes' trashes? If you don't want to delete something immediately, don't. –  Jason Salaz Sep 27 '11 at 15:24
    
Honest Answer: Because I want to recover space on a USB stick (and thus need to empty the trash while it is mounted) but don't want to empty the trash on my main volume (because I'm afraid of needing to recover something from my recently-worked on set of files). –  Bill Nace Sep 27 '11 at 21:57
    
You might find my answer to this related question helpful. It's not exactly what you're looking for, but it might help. –  Daniel Lawson Sep 28 '11 at 4:41
add comment

4 Answers 4

up vote 1 down vote accepted

I had a bit of time and the occasional need for something like this, so I thought I'd try writing up a quick AppleScript to do this.

The following AppleScript should do what you need. Paste it into a new AppleScript Editor document and save it as an application, then you can drag a volume onto it to delete only its files from the Trash.

If you drag your startup disk to it, it will delete files from the current user's Trash in their home folder.

If you drop multiple volumes on the script, it will empty all of their trashes.

The script only looks at the current user's trashes on volumes. On non-startup volumes (partitions & external drives), the user's trash is in /Volumes/volumeName/.Trashes/userID/; on the startup volume, it looks in ~/.Trash/.

It will ignore anything dropped onto it that is not a volume.


There are a few properties you can change to alter how it behaves.

Prompt for Secure Delete - If you want the script to ask you each time whether to delete securely, set the askForSecureEmpty property to true (at the top of the script).

Default Delete Command (rm or srm) - If you don't want the script to ask you each time, set askForSecureEmpty to false, then set rmDefault to either rm for normal or srm for secure.

Disable Trivial Dialogs - The script will show a dialog if it didn't find any Trash files to empty, e.g. if there were no files in that volume's Trash. To disable these, change the property, showDialogs to false. If there is an actual error while trying to delete files from a volume's Trash, you will still get an error message.


Disclaimer

The rm command can be very destructive. I wrote this script fairly quickly and only tested it on my own Mac, so please use it with caution and at your own risk. That said, it really shouldn't do anything to any files that are not already in a Trash folder somewhere.

One scenario I have not tested that could cause a problem is if you have two or more volumes with the same name.

Any ideas to clean up or improve the script are welcome.

-- Script to empty selected volumes' trashes --

property askForSecureEmpty : false -- change to true if you want to choose each time script is used
property rmDefault : "rm" -- command to use when askForSecureEmpty is "false"; use "rm" for regular, "srm" for secure
property showDialogs : true

on run
    set theVolumes to {choose folder}
    emptyTrash(theVolumes)
end run

on open theVolumes
    emptyTrash(theVolumes)
end open

on emptyTrash(theVolumes)
    if askForSecureEmpty then
        set useSecure to display dialog "Use Secure Empty Trash?" buttons {"Cancel", "No", "Secure"} default button "Secure"
        if useSecure is "Secure" then
            set rmCommand to "srm"
        else
            set rmCommand to "rm"
        end if
    else
        set rmCommand to rmDefault
    end if

    -- Get the user ID to empty only the current user's Trash --
    set userID to user ID of (system info)

    -- Set up a counter to later determine if any volumes were dropped on the script --
    set volumeCount to 0

    -- Cycle through each item dropped on the script to empty its Trash --
    repeat with theVolume in theVolumes
        if kind of (info for theVolume) is "Volume" then --ignore anything that's not a volume
            set volumeCount to volumeCount + 1
            set volumeName to name of (info for theVolume)

            -- Check if we're working on the startup disk, if so use user's home Trash --
            tell application "System Events" to set startupVolume to name of startup disk
            if volumeName = startupVolume then
                set trashPath to "~/.Trash/"
            else
                set trashPath to quoted form of (POSIX path of theVolume & ".Trashes/" & userID & "/")
            end if

            -- Try emptying the trash --
            try
                do shell script "cd " & trashPath --make sure the expected Trash folder exists
                if (count (paragraphs of (do shell script "ls -l " & trashPath))) > 0 then
                    try
                        do shell script "cd " & trashPath & "; " & rmCommand & " -R ./*" --try to empty the trash
                    on error
                        display alert "Error on volume " & volumeName as warning message "There was an error trying to delete the files." buttons {"Cancel", "OK"} default button "OK"
                    end try
                else
                    if showDialogs then display dialog "The Trash for volume '" & volumeName & "' appears to be empty." buttons {"OK"} default button "OK"
                end if
            on error
                if showDialogs then display dialog "No Trash folder on '" & volumeName & "' for this user." buttons {"OK"} default button "OK"
            end try
        end if
    end repeat

    -- Report an error if no volumes were found --
    if volumeCount = 0 and showDialogs then display dialog "No volumes found."
end emptyTrash
share|improve this answer
    
This is sweet! Works very well. Love that I can just drop a volume on it -- don't have to open applications, run through menus, type anything, etc. Nice work! –  Bill Nace Sep 28 '11 at 18:12
add comment

I haven't tried it myself, but had this conversation with someone else who used SmartTrash. Give it a go.

share|improve this answer
    
+1. SmartTrash is the simplest way to do this. –  TJ Luoma Sep 28 '11 at 3:20
add comment

I use Cocktail for this, which I already have for other reasons.

share|improve this answer
1  
A link would be wonderful. –  Jason Salaz Sep 27 '11 at 15:34
    
Mac software can often be found at places like download.cnet.com/mac –  GEdgar Sep 27 '11 at 18:01
    
A direct link to Cocktail from a vetted source, would be wonderful. By direct link I don't mean directly to the software, but perhaps the software's homepage / the developer's site. –  Jason Salaz Sep 27 '11 at 18:04
1  
Here's where I explain what I'm getting at. An answer is supposed to be a nearly definitive resource. Simply telling the user to go off in $x direction is not the intention of Stack Exchange. For many of the same reasons why an answer should not just be a link, an answer should also provide an answer and an explanation. Putting pertinent details into an answer makes your answer that much better. –  Jason Salaz Sep 27 '11 at 20:04
1  
GEdgar, care to explain how Cocktail answers my question? I downloaded it (from the link you found, thanks!). But I don't see any mechanisms to clear the trash (easily missed, this thing has dozens of options). I see a button to Force Empty the trash, but that is only on the system disk. Certainly don't see anything that I easily get to. –  Bill Nace Sep 27 '11 at 22:05
show 2 more comments

Here's one freeware option (Smart Trash and Cocktail are commercial): Super Empty Trash

Seems to work fine - very simple, delete from one volume at a time.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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