Folder Action - Move files to trash...

First let me say I am a total newbe to Apple Script so THANKS to anyone that is interested enought to help!

That said I am trying to write a script that will move certain files from my download folder to the trash when ever they are received via email.

This is what I have so far… What am I doing wrong?:
on adding folder items to this_folder after receiving these_items
tell application “Finder”
activate
beep
if name of document file is “signature.asc” then
try
move to trash
end try
end if
if name of document file is “Untitled” then
delete reference
end if
if name of document file is “smime.p7s” then
delete reference
end if
end tell
end adding folder items to

Try this:

on adding folder items to this_folder after receiving these_items
	tell application "Finder" to ¬
		delete (items of this_folder whose name is in {"signature.asc", "Untitled", "smime.p7s"})
end adding folder items to

jj:

You Rock!!!

Thank you soo much. this seems to work perfectly. The only question is now what current books or pdf-s out there would you recomend for learning more and keeping on hand as refs.

eric

Best online resources for me are:
AppleScript For Absolute Starters: http://www.applescriptsourcebook.com/tips/AS4AS.html
AppleScript Language Guide: (look at the link in our front page)
Our FAQ: http://macscripter.net/faq/
The various sections in MacScripter will also offer lots of source code, which is allways an interesting option.

I am interested in this script as well. However, my twist is that the files I wish to selectively delete have slightly different names from each other, but all start with ‘qe’ and end with ‘.tmp’.
Would anyone know how to alter the following to only delete files with these credentials?

on adding folder items to this_folder after receiving these_items
tell application “Finder” to ¬
delete (items of this_folder whose name is in {“qe55.tmp”})
end adding folder items to

The idea would be that as soon as a file dropped into a certain folder and began with ‘qe’, the script would move it to the trash. Any help appreciated.

Timothy

... items of this_folder whose name starts with "qe" and name ends with ".tmp"

Thanks for the help, but it does not appear to work for me. I have save dthe script as a script and placed it in the Folder Actions Script folder and doen the FAS setup, and then attached the script as an action to a sample folder. When I dropped in a sample file, nothing happened. (?)
OS 10.3.6
Script used:
on adding folder items to this_folder after receiving these_items
tell application “Finder” to ¬
delete (items of this_folder whose name starts with “qe” and name ends with “.tmp”)
end adding folder items to

Hmmm… Works fine here.
What does it happen if you include this line before the tell-finder statement?

display dialog "I'm being executed!"

If it doesn’t work, most tipically FA are not enabled. It it does, what does it happen if you run it manually? Eg, place in a dir some files whose name starts with “qe” and ends with “.tmp”, and run this:

set this_folder to alias "path:to:dir:"
tell application "Finder" to delete (items of this_folder whose name starts with "qe" and name ends with ".tmp")

OK, that works now! Thanks jj, much appreciated. I’m pretty sure it was a setup issue. All happy now.

I’m trying to perform a similar action, but I’m told that I don’t have enough access.

{items in this_folder whose modification date < ((current date) - 7 * days)}