Clear Downloads Folder using AppleScript

Apr 19, '11 07:30:00AM

Contributed by: cycle4passion

With time the Downloads folder gets filled with a variety of items. In order to clear it using the dock, items have to be dragged to the Trash individually [crarko adds: or you can navigate to the folder in Finder, do a 'Select All' and trash them]. Here is a tiny AppleScript that presents an alternative.

Run AppleScript Editor and copy and paste the following code. You'll have to change the path to match your username using AppleScript Editor. Next, save it as an application named 'Clear Downloads' into your Downloads folder. Feel free to add a custom icon if you wish. To test, just click your downloads stack on the dock and select 'Clear Downloads.'

Here's the script:

try
  tell application "Finder"
  move (files of alias "Macintosh HD:Users:YOURUSERNAMEGOESHERE:Downloads" whose name is not "Clear Downloads.app") to trash
  end tell
on error -- oops, couldn't move the file
  display dialog ("Error") buttons {"OK"}
end try

[crarko adds: I debated publishing this one, but I think the basic idea is a sound one. I've used a similar script to create a Trash item on my desktop, and then attached the script as a Folder Action to move what I put in it to the actual (hidden) Trash folder.]

Comments (9)


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