Create a dynamic Trash button that changes when your trash is full or empty.

I've had BTT for about a week and only just started looking at Applescripting for the first time yesterday but I put this little script together for the trash that I'm pretty happy with. It was hobbled together from various bits of code I found on these forums and elsewhere.

You need to create a widget with 'Run Apple Script' as the function. Then you set up the icons to show an empty and full trash with true written in the regex setting. Use the following code in the same section and put Empty Trash as your pre-defined action. I've got 0.5 seconds for 'Execute every' so it updates as soon as you trigger it. I'm sure someone who knows what they're doing can probably improve on it but there you go.



Full and empty examples, had to put a sparkle on the clean bin so it didn't look unbalanced.

tell application "System Events"
set trash_size to do shell script "du -sk ~/.Trash/ | awk '{print $1}'"
set trash_size to trash_size / 1024
if trash_size > 0.01 then
return true
else
return false
end if
end tell

try
return trash_size
end try