On 28/01/2009, at 10:47 PM, Jim Brandt wrote: <Snip>
The error happens immediately after the first file in the folder moves. No stalling, no wait cursor, just the error.
If I run the pair again (script B calling script A) it moves the next file and stops with an error.
If I run script A standalone, all files move, with no error.
This was an attempt to not duplicate code, as script A does more than move these files, its just that it's at this part of the script that I get the error. The first part of the script "A" builds an email that sends all the files as attachments to a specific email address. That part of the script works both as standalone and when called from the second script. Its just the moving of the files part that fails.
Thanks again.
Jim
Jim, I don't know if this will help, but I have two scripts doing similar things to yours, and struck problems.
In the script being called,
1. When referring to the actual emails, I found it necessary to declare the variable referring to the processing email as a global, and also to pass the variable between subroutines. If I did not do this, references to the email became 'unstuck'.
global emailreference property MailBoxStoreName : "* items to store"
on Mainroutine() tell application "Mail" activate tell application "System Events" to tell process "Mail" set W to every window repeat with A in W tell A try if name of A is in {"Activity Viewer", "Addresses", "Mail Connection Doctor", "Previous Recipients", "Photo Browser", "Fonts", "Colors"} then click button 1 of A end try end tell end repeat end tell set tempStore to messages of mailbox MailBoxProcessName repeat with emailreference in reverse of tempStore my SubRoutine1(emailreference) end repeat end tell end Mainroutine
on SubRoutine1(emailreference) --do stuff my subroutine2(emailreference) end SubRoutine1
on subroutine2(emailreference) --do stuff end subroutine2
2. When moving files, never refer to the files directly, but as a variable
repeat with thefiles in contents of thefolder -- this will bomb in a called script after one file is moved, as the finder refreshes, and the variable loses track of the remaining files --move file end repeat
set TheFileList to contents of thefolder -- this works repeat with thefiles in TheFileList --move file end repeat
Hope this helps
Regards
Santa |