Display the size of the trash prior to emptying

Feb 28, '03 09:39:00AM

Contributed by: xchanyazy

I posted this to this thread on the forums last night, and got a bunch of emails saying how useful it was ... so I figured I'd submit it to the main site. I'll throw in the relevant bits below, but the link probably explains it better than I...

I was kind of bored, so I decided to mess around. I came up with this script, which I then saved as a run-only application, and threw in my dock next to the trash can. I'm sure it can be improved a lot (for instance, this only counts the amount in your user trash (not any other volumes), but it works for me.

set amount to do shell script "du -sk ~/.trash | awk '{print $1}'"
display dialog "There are " & amount & " kb in trash.  Would you like to empty?"
if button returned of result = "OK" then
  tell application "Finder"
    empty trash
  end tell
end if
Maybe I should explain what (I think...) this code does.

The first line uses the 'du' terminal command and then takes the kilobytes from the first column and stores it in a variable. The next line displays the message including the size of the trash. The next line checks to see if you said OK, and if it does, tells the finder to empty the trash. That's it. To change it to megabytes instead of kilobytes you could just insert this between the first and second lines:
set amount to amount / 1024
And change the dialog from kb to mb.

[robg adds: I tested this, and it worked as described...]

Comments (41)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030226135215160