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

Clear Downloads Folder using AppleScript Desktop
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.]
    •    
  • Currently 2.67 / 5
  You rated: 1 / 5 (6 votes cast)
 
[12,508 views]  

Clear Downloads Folder using AppleScript | 9 comments | Create New Account
Click here to return to the 'Clear Downloads Folder using AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Clear Downloads Folder using AppleScript
Authored by: ChaChi on Apr 19, '11 07:41:26AM
Just a FYI... You should use (path to downloads folder) in place of the hard coded path. Hard coding paths in a script is a bad idea.

[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: Frederico on Apr 19, '11 09:44:22AM

I agree. You could also use (path to me) and employ this script in any other folder, albeit the app name becomes relevant. Perhaps "Empty This Folder" is more universal.

On first read, I could not readily accept this as a good hint; but when I accepted the premise that some users really do use the Downloads folder from the Dock and don't quite always get the concept of exploring Finder directly, and that this essentially adds a constant command to the Dock Grid (or Stack), I had to kinda come around to the idea.

Seems like effort should be made to force it to sort to top or preferably the bottom of the list, though, when the folder is not set to Date Added, so you don't have to hunt for it.



[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: Frederico on Apr 19, '11 10:29:01AM
I must be really bored today:

tell application "Finder" to move (every item of (container of item (path to me) as alias) whose name is not (name of item (path to me) as text)) to trash

Save the above single line as a compiled application and name it whatever you want; I suggest 'Clear This Folder' or 'Move Contents of This Folder to Trash'.

Be careful where you run it, because it will Trash everything in its directory.

I thought about using do shell script and rm, but this method allows the user to recover with a simple Command-Z (Undo Move).

[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: leamanc on Apr 19, '11 05:03:51PM

Nice one! I like a simple one-liner, and will be employing this in my Downloads folder...which does get way overloaded with junk seemingly all the time.



[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: Andrew J Freyer on Apr 19, '11 08:13:18AM

In lieu of accumulation and occasional clearing, I HIGHLY recommend using Hazel. http://www.noodlesoft.com

Hazel sorts your downloaded files based on rules that you set up. Movies can be sorted with movies, TV shows can be sorted with TV shows, PDFs can be sorted with PDFs. And most importantly, you can delete files "of a certain age."

---



[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: bglnelissen on Apr 19, '11 10:05:33AM
6 million ways to empty the trash, here is mine. this script is called 'download2trash.command' and opens everytime I login.

#!/bin/bash
# b.nelissen

# move contents of downloads folder to trash (I want a clean downloads folder every time I login)
mv ~/Downloads/* ~/.Trash/
Edited on Apr 19, '11 10:07:05AM by bglnelissen


[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: dogboi on Apr 19, '11 10:26:00AM
I generally just remove everything from the command line.
cd ~/Downloads
rm -rv *
Obviously, though, if you use that method, there's nothing in the trash to recover.

[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: tom larkin on Apr 19, '11 10:40:52AM

I would just use a login hook, or a log out hook and use some sort of user detection (like who owns the console) to fill in the path of what user is using it. Then it would work for all users on your system.



[ Reply to This | # ]
Clear Downloads Folder using AppleScript
Authored by: alastor933 on Apr 19, '11 10:52:18PM
I may be overcritical, but as a hint this is a tiny one. I have an armful of little helpers like this. Shall I submit them all? Oh wait, there is a forum for that.

[ Reply to This | # ]