PDA

View Full Version : Why isn't my AppleScript Working?




cbrain
Mar 11, 2007, 03:07 PM
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:

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
Mar 11, 2007, 03:29 PM
I'm not an AppleScript expert, but don't you have to further define the location of the Downloads folder? Something like this:

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

cbrain
Mar 11, 2007, 03:31 PM
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
Mar 11, 2007, 06:12 PM
You could use a do shell script to do it


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


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

lancestraz
Mar 11, 2007, 10:04 PM
Where is the folder "Downloads"?
Is it "Macintosh HD:Users:your username:Downloads". Or something else?

xUKHCx
Mar 11, 2007, 10:30 PM
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


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.

cbrain
Mar 12, 2007, 11:37 AM
Thank You! That Worked!