Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automatically empty the trash when items are trashed System
I recently had a friend who is in the midst of switching ask me if it's possible to have the Trash automatically emptied when you drag items to it. Apparently this is an option in Windows, but there is a way to do it in Mac OS X as well. So, I thought others might find it useful.

You need to have Folder Actions enabled in order to do this -- double-click the AppleScript menu.menu file in /Applications -> AppleScript (if you haven't done so before), then click the script icon in the menu bar and select Folder Actions -> Enable Folder Actions.

Here are the steps:
  1. Create and save this AppleScript (using Script Editor in /Applications -> AppleScript) in the /Library -> Scripts -> Folder Action Scripts:
    on adding folder items to this_folder after receiving added_items
      try
        tell application "Finder" to empty
      end try
    end adding folder items to
  2. From the Folder Actions menu in the Script icon in your menu bar, choose "Attach Script to Folder." Then choose the script you just created. When it asks what folder to attach it to, type ~/.Trash in the Go text field and press Return. Then click Choose.
After you do this, the Finder will automatically empty the trash every time you put items in it. Use with extreme care.

[robg adds: A couple of comments on this one ... first, it's obviously quite dangerous! Once dragged to the trash, the item is gone for good. Second, I prefer to keep my folder action scripts particular to my user, so I store them in my user's Library -> Scripts -> Folder Action Scripts folder, not the system-wide Library. You may have to create this folder structure if you've not done so previously. Finally, I tested this script, and it works as described ... after proving that point, I disabled the script (Script menu -> Folder Actions -> Remove Folder Actions) immediately, as I don't trust myself that much!!]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,457 views]  

Automatically empty the trash when items are trashed | 9 comments | Create New Account
Click here to return to the 'Automatically empty the trash when items are trashed' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically empty the trash when items are trashed
Authored by: lgoldman on Aug 06, '03 11:53:20AM

With me, it would only work the first time I put something in the trash. Each time thereafter I have to do the Attach Script step again.



[ Reply to This | # ]
A cron approach
Authored by: maxgraphic on Aug 06, '03 01:13:02PM

This approach empties your trash on the hour of files that haven't been accessed in 90+ minutes.

$ crontab -e
[this launches vi or your default editor]
Add the line:
0 * * * * find ~/.Trash -amin +90 -exec rm -fr {} \;

---
Design your own business cards and more
http://www.designyourowncard.com/



[ Reply to This | # ]
A cron approach
Authored by: Mikey-San on Aug 06, '03 11:25:44PM

Ew ew ew ew!

The beauty of the empty trash script is that if a file is in use, the OS won't allow it to be deleted. You'll get a warning dialog instead.

With rm, you might kill files something is still using. That could suck.



[ Reply to This | # ]
A cron approach
Authored by: maxgraphic on Aug 07, '03 01:53:09PM

Then again, the beauty of rm is that it'll empty the trash of stubborn items that the Finder might claim are in use that aren't.

---
Design your own business cards and more
http://www.designyourowncard.com/



[ Reply to This | # ]
A cron approach
Authored by: chally on Sep 14, '06 02:29:30AM
I've found that without the following in the find command, the trash directory itself is killed, causing an "auto-empty" when an item is dragged to the trash (at least the finder figures it out and warns you though.)

    -not \( -name .Trash \)

So the whole crontab entry would be

    find ~/.Trash -not \( -name .Trash \) -exec rm -fr {} \;

Still, this solution is somewhat useless to me because it does not handle my Power Mac G5's second drive or temporarily mounted drives. I looked into handling that and though I think I basically groked what's going on I determined:

  1. I'm not sure enough what I'm doing
  2. Deleting things automatically is scary
  3. To do the job properly, if I knew what I was doing would require a fairly complex script.
Use at your own risk.

[ Reply to This | # ]
Automatically empty the trash when items are trashed
Authored by: Brennan on Aug 06, '03 08:38:14PM
What about getting the Trash to suggest that it be empted when it contains more than x MB
property oneMB : 1000000
property maxSize : oneMB * 10

on adding folder items to thisFolder after receiving theseFiles
 
 try
  set thisFolder to choose folder
  set fldrPath to (thisFolder as string)
  set itemz to (list folder thisFolder)
  
  set collectedSize to 0
  repeat with i in itemz
   set thisFile to (fldrPath & i) as string
   set fileinfo to info for thisFile
   set collectedSize to collectedSize + (size of fileinfo) -- bytes!
  end repeat
  
  if collectedSize > maxSize then
   set MBs to (collectedSize / oneMB) as string
   set str to "The trash contains " & MBs & "MB. " & return
   set str to str & "Empty it?"
   set dr to (display dialog str)
   set br to dr's button returned
   if br is "OK" then
    tell application "Finder" to empty
   end if
  end if
  
 on error msg number n
  display dialog "Script error: " & msg
 end try
 
end adding folder items to


[ Reply to This | # ]
Automatically empty the trash when items are trashed
Authored by: Accura on Aug 07, '03 04:23:48AM

Does this work is you drag something to that trash that resides on another disk?

---
"The time has come," the walrus said. "To talk of many things..."



[ Reply to This | # ]
Automatically empty the trash when items are trashed
Authored by: Zoz on Aug 07, '03 02:24:24PM

It's worth mentioning the 'Standard Short Cuts' here

Selection + {Command} + {Alt} + {Delete}
==> Move selection directly to the Trash

{Command} + {Shift} + {Delete}
==> Empty the trash

If in Finder Preferences, you have show warning switched off
then those two keyboard short cuts will do the job for you.
(otherwise also need {return} to OK the deletion.)
- and will work on any Mac - not just 'customized' ones.



[ Reply to This | # ]
Automatically empty the trash when items are trashed
Authored by: nathanst on Aug 08, '03 02:50:45PM

Actually, you just need COMMAND-DELETE to move something to the trash.



[ Reply to This | # ]