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

Empty the trash from any application via AppleScript Apps
One thing that has always annoyed me in OS X is that the Empty Trash shortcut only works in Finder, so I wrote an AppleScript that lets you empty the trash from any application. First you'll need to download Spark. Make sure the Spark daemon is running and that 'Start Spark Daemon at Login' is checked in the General tab of the Preferences window. Once you have it set up, hit Command-1 to create a new AppleScript shortcut. Copy and paste this code into the window that comes up: The showWarning property tells the script whether or not to show the confirmation dialog when you empty the trash. If it's set to true then you'll get the standard warning, and after you hit OK or Cancel, you'll be taken back to whatever app you were in. If it's false, then the trash will just empty itself in the background.

Once you've pasted the script into the new window, add a shortcut for it in Spark, give it a name, and click the Create button. Now you'll be able to call the script from any application using the shortcut you defined. You could probably do the same thing in Snow Leopard by creating a service and then assigning it a custom shortcut in the Keyboard preference pane, but I haven't upgraded yet so I haven't tried it.
    •    
  • Currently 1.78 / 5
  You rated: 3 / 5 (9 votes cast)
 
[7,498 views]  

Empty the trash from any application via AppleScript | 20 comments | Create New Account
Click here to return to the 'Empty the trash from any application via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Empty the trash from any application via AppleScript
Authored by: yubbie2 on Sep 25, '09 08:46:28AM

Wait... can't you just right-click on the trash and choose "Empty Trash"?



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: esetleges on Sep 26, '09 02:39:45AM

Command+Tab and then Command+Shift+Delete (Backspace)



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: asmeurer on Sep 25, '09 09:29:18AM

I'm not quite sure why you would want that shortcut to work in every application. Are you constantly filling up and emptying your trash from every application? You said that this is something about OS X that bugs you. Does Windows have this strange feature?



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: asmeurer on Sep 25, '09 09:30:18AM

I'm not quite sure why you would want that shortcut to work in every application. Are you constantly filling up and emptying your trash from every application? You said that this is something about OS X that bugs you. Does Windows have this strange feature?



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: Dr. T on Sep 25, '09 10:11:36AM

You don't need any outside utilities. Launch AppleScript Editor (or Script Editor). Open Preferences. Check "Show Script menu in menu bar." Use the script below. (Add a warning about the irreversibility of emptying trash, if desired.)

tell application "Finder"
empty trash
end tell

Save this as a run only application with no startup screen. Put it in ~/Library/Scripts/ (current user) or /Library/Scripts/ (all users). It's now available for every application that retains the menu bar.



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: David Allen on Sep 27, '09 07:27:28AM

And this provides him with a keyboard shortcut how?

Oh, it does not.

Which is what the post is about, a keyboard shortcut to accomplish emptying the Trash while away from the Finder.

---
David Austin Allen
Monterrey, NL, MX



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: rayene.benrayana on Sep 25, '09 10:56:49AM
Empty the trash from any application via AppleScript
Authored by: leamanc on Sep 25, '09 12:59:29PM

I agree with a lot of the commenters here...this is just not necessary. The Trash's contextual menu in the Dock is plenty good for me, and always available in any app.

If you have to have an AppleScript to do this, there are a lot shorter scripts out there (see the three-liner above) that will do the trick, and can go in your Script Menu. You do have the Script Menu in your menubar, right? If not, you are missing out on some great stuff that is only a click away, and highly customizable.



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: David Allen on Sep 27, '09 07:32:11AM

Well, the Script menu is fine. Now can you tell him how to assign a keyboard shortcut to accomplish that script, which is what the post is about, a keyboard shortcut. Not a dropdown menu. Not a contextual menu. A keyboard shortcut.

We all use our Macs differently. Some folks are keyboard oriented. Others are mouse oriented.

For all you know he is blind and uses the keyboard for everything.

Often the criticism is just being pissy!

---
David Austin Allen
Monterrey, NL, MX



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: Mac Berry on Sep 27, '09 09:54:58PM

I think you're right that the hint is specifically about adding a keyboard shortcut, but the hint title, and in fact the hint itself, doesn't say that, it's just implied.

The comments about being able to use the scripts or contextual menus are perfectly reasonable responses to the hint title and it's first sentence. The title suggests you can't empty the trash from any application, whereas in fact you can.

Anyway, even if you are keyboard centric, I personally think this hint is a little OTT, unless you have so little disk space that you need to empty the Trash every 5 minutes. If you do, or simply don't like to use the trash, what you really need is a Windows like option to permanently delete immediately.



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: jazzmaniac on Sep 25, '09 01:08:35PM

I've been truly astounded since Apple dropped the SnapBack button to discover how few people used it. To me it was one of Safari's main advantages. And you could use a drop down to manually reset your "Snapback page" any time you wanted.
Since Safari 4 I've been searching for a hack to restore this feature (along with the progress bar in the URL field....a spinning arrow tells me nothing except that, by golly, the page is loading to SOME degree....but had no luck.



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: TvE on Sep 26, '09 03:20:14AM

And what does this have to do with a global empty trashcan command???

;-)



[ Reply to This | # ]
I'm with you ...
Authored by: tice on Sep 26, '09 12:11:45AM

Actually I like to push a button much more instead of point and click. I use the freeware Spark for that to.

Unfortunately there is no free F-button left on the new MacBook Pro, so now I have to push fn-F12, but still much faster then to target the trash, right-click an choose emty trash.



[ Reply to This | # ]
I'm with you ...
Authored by: psedog on Sep 26, '09 08:35:59AM

All you have to do is press.
cmd+shift+delete

This will empty your trash without any applescript coding. I'm kind of surprised that this wasn't brought up before.



[ Reply to This | # ]
I'm with you ...
Authored by: Dr. T on Sep 26, '09 09:59:07AM

Command-shift-delete is used by some applications for a different purpose than emptying trash. For example, in the old outliner More (that I used for twelve years), that keystroke combination merged two topic headings.

The Script Menu method works with every application that retains the menu bar.



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: psedog on Sep 26, '09 08:32:30AM

So, I'm confused here. I can empty my Trash bin from any application without any special mods at all.
cmd+shift+delete

It's so simple. You already press cmd delete to delete something right? Just hit shift afterwards.



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: TvE on Sep 27, '09 12:12:02AM

Then you must have forgotten some modification you have made…



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: David Allen on Sep 27, '09 07:34:31AM

Sorry, that does not do anything.

---
David Austin Allen
Monterrey, NL, MX



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: Mac Berry on Sep 27, '09 10:10:19PM

Not being funny here, but is posting very straightforward scripts to do specific things really the purpose of Mac OS X Hints? I mean, if every action that someone writes a script to perform becomes a hint, doesn't that dilute the real undocumented stuff?

I'm not suggesting that a listing of useful scripts, for those who can't/don't want to write their own isn't handy, just that I personally don't see the main Mac OS X Hints list as the right place for it unless the script really does display a bit of lateral thinking (Empty Trash doesn't!).

This hint might be better titled "run scripts from any application using keyboard shortcuts", and be a heads up to get Spark, as that's the more useful part of it I'd have thought. There could be another hint titled "do things the OS doesn't do out of the box", with the text "write a script"!



[ Reply to This | # ]
Empty the trash from any application via AppleScript
Authored by: Anonymous on Sep 28, '09 12:27:44PM

Agreed. It does dilute. Hints need reorganizing by category.



[ Reply to This | # ]