Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cbrain

macrumors 65816
Original poster
Dec 9, 2006
1,049
0
North-East, UK
Hi.

I am trying to write an AppleScript that empties my downloads folder. However, whenever I run the script, I get the dialog box, but then I get this error: "Finder got an error: Can't get folder "Downloads" of folder "Home".

The script is as follows:

Code:
set userResponse to the button returned of (display dialog "Are you sure you want to empty your downloads folder?" buttons {"No", "Yes"} default button 2 with icon caution)
if userResponse is "Yes" then
	tell application "Finder"
		empty folder "Downloads" of the folder "Home"
	end tell
	
end if

There is defiantly a folder called "Downloads" in my home folder. Is there something wrong with my code?

Thanks.
 

WildCowboy

Administrator/Editor
Staff member
Jan 20, 2005
18,483
2,984
I'm not an AppleScript expert, but don't you have to further define the location of the Downloads folder? Something like this:

Code:
empty folder "Downloads" of folder "Home" of folder "Users" of startup disk
 

cbrain

macrumors 65816
Original poster
Dec 9, 2006
1,049
0
North-East, UK
I've just tried that, but this time I get: "Finder got an error: Can't get folder "Downloads" of folder "Home" of folder "Users" of startup disk."
 

semaja2

macrumors 6502a
Dec 12, 2005
576
18
Adelaide
You could use a do shell script to do it

Code:
do shell script "rm -Rf ~/Downloads/"

im not sure if thats the right command but you can do something like that
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
Where is the folder "Downloads"?
Is it "Macintosh HD:Users:your username:Downloads". Or something else?
 

xUKHCx

Administrator emeritus
Jan 15, 2006
12,583
9
The Kop
You do not need to put home in quotes also the empty contents command wont work. I would do it this way:

set userResponse to the button returned of (display dialog "Are you sure you want to empty your downloads folder?" buttons {"No", "Yes"} default button 2 with icon caution)
if userResponse is "Yes" then
tell application "Finder"
if the folder "Downloads" of home exists then
delete entire contents of folder "Downloads" of home
else
display dialog "Folder not found"

end if
end tell
end if


You could use a do shell script to do it

Code:
do shell script "rm -Rf ~/Downloads/"

im not sure if thats the right command but you can do something like that

This is actually delete the folder "Downloads" which would cause an error the next time the application is run. Also it is not the safest method as it actually deletes the files right there and then while the above method just moves them to the trash so then can be recovered incase the files were deleted accidentally.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.