Hello
This edited script works flawlessly :
(*
set thisFolder to (path to desktop as text) & "Printed:" as alias
my adding_folder_items(thisFolder, {})
on adding_folder_items(thisFolder, {})
*)
on adding folder items to thisFolder after receiving addedItems
(*
Here thisFolder is an alias so we can't code « of folder thisFolder » *)
tell application "Finder"
set added_Items to every file of thisFolder
set this_Folder to thisFolder as text
repeat with anItem in added_Items
set anItem to anItem as alias
if the name of anItem contains "estimate" then
try
move anItem to folder (this_Folder & "Estimates")
end try
else if name of anItem contains "invoice" then
try
move anItem to folder (this_Folder & "Invoices")
end try
else if name of anItem contains "payment" then
try
move anItem to folder (this_Folder & "Payments")
end try
end if
end repeat
end tell
end adding folder items to
--end adding_folder_items
I left some extraneous instructions (disabled of course) which I use to test this kind of scripts.
I don’ treat the addedItems set of files because sometimes one or two files aren’t passed because the Finder is a bit lazy to treat folder actions.
I added try/end try blocks because I don’t know what you want to do if there is already a file xxx estimate.yyy in the Estimates subfolder.
I wish to add that I’m puzzled by the behavior of your original applet.
Reading it I was sure that it would fail because the move instructions and the one extracting the name of each files are out of the tell application “Finder” block.
When I ran it, I discovered that AppleScript execute the script as if the end tell was not where it is written but as if it was at the very end of it.
So, this day is a good one : I learnt something !
I’m not sure that I was clear enough so I post the log report issued by the original script (with a single change :
I was forced to remove the redondant word folder in the instruction :
set addedItems to every file of folder theFolder
It must be :
set addedItems to every file of theFolder
tell current application
path to desktop as text
→ “Macintosh HD:Users:xxxxxx:Desktop:”
end tell
tell application “Finder”
get every file of alias “Macintosh HD:Users:xxxxxx:Desktop:Printed:”
→ {document file “.DS_Store” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk, document file “CodeSigningGuide estimate co.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk, document file “CodeSigningGuide estimate copie.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk, document file “CodeSigningGuide.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk, document file “Convert to header row copie.scpt” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk}
get name of document file “.DS_Store” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “.DS_Store”
get name of document file “.DS_Store” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “.DS_Store”
get name of document file “.DS_Store” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “.DS_Store”
get name of document file “CodeSigningGuide estimate co.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “CodeSigningGuide estimate co.pdf”
move document file “CodeSigningGuide estimate co.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk to “Macintosh HD:Users:xxxxxx:Desktop:Printed:Estimates”
→ document file “CodeSigningGuide estimate co.pdf” of folder “Estimates” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ error number 0
get name of document file “CodeSigningGuide estimate copie.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “CodeSigningGuide estimate copie.pdf”
move document file “CodeSigningGuide estimate copie.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk to “Macintosh HD:Users:xxxxxx:Desktop:Printed:Estimates”
→ document file “CodeSigningGuide estimate copie.pdf” of folder “Estimates” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ error number 0
get name of document file “CodeSigningGuide.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “CodeSigningGuide.pdf”
get name of document file “CodeSigningGuide.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “CodeSigningGuide.pdf”
get name of document file “CodeSigningGuide.pdf” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “CodeSigningGuide.pdf”
get name of document file “Convert to header row copie.scpt” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “Convert to header row copie.scpt”
get name of document file “Convert to header row copie.scpt” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “Convert to header row copie.scpt”
get name of document file “Convert to header row copie.scpt” of folder “Printed” of folder “Desktop” of folder “xxxxxx” of folder “Users” of startup disk
→ “Convert to header row copie.scpt”
end tell
Yvan KOENIG (VALLAURIS, France) lundi 27 août 2012 17:07:10