Script to move contents of one folder to the trash & empty trash

Apoligies in advance if this is something really simple…I literally just discovered AppleScript about a week ago. :stuck_out_tongue: Have been a Mac user since Sept. 09.

I am looking for a script that will move the contents of a folder (specifically, my Downloads folder) to the Trash, and then empty the trash.

Usually, my downloads folder is cluttered up with .pdf’s and other various documents downloaded and it would seem very handy to have a script on my desktop which would replace this process.

Thanks :slight_smile:

Model: Late 2009 MacBook Pro 13"
AppleScript: AppleScript 2.1.1
Browser: Firefox 3.5.7
Operating System: Mac OS X (10.6)

The most elegant way to do this for about $20 is to use Hazel because it allows you to be selective about what happens in the downloads folder and when it happens. If you don’t want to spring for that then scripting it is straight-forward but dangerous in my view. Do you really want a script?

Yes, I’m aware of the risks. I don’t keep any inportant documents or files in that folder (at the very least nothing that I can not easily re-download if needed) and I would like to save some time in deleting those files.

If you want it to be a little closer to AppleScript, you can use this:

tell application "Finder"
	set myDownloadFolder to ((path to home folder as text) & "Downloads:") as string
	set everyDownload to (every item of alias myDownloadFolder)
	
	-- display dialog "You're about to delete " & ((count everyDownload) as string) & " items. Do you wish to continue?" buttons {"No", "Yes"} default button 2 cancel button 1
	
	repeat with i in everyDownload
		delete i
	end repeat
	
	empty trash
	-- display dialog "Done!" buttons "OK" default button 1
end tell

Hope you like it,
ief2

Hello ief2,

Your English and scripting are quite good. I just have one question. Did you use AppleStudio to write these apps on your website?

Thanks,
Tommy

Well, I’m glad someone is interested :smiley:

I used AppleScript Studio, which is a part of Xcode. Interested?

or easier


set myDownloadFolder to (path to downloads folder)
tell application "Finder"
	delete items of myDownloadFolder
	empty
end tell

:wink:

The Pro speaks :stuck_out_tongue: