I have a script that runs daily on my desktop machine (PowerMac running 10.4.11). Occasionally it crashes with an error -609 Finder got an error: connection is invalid. When this happens, the Finder has crashed and relaunched. I have never before been able to track down the circumstances that cause this (the frequency is about twice a month).
I'm testing this script on my MacBook (running 10.6.4), and it is crashing every time at the same place. The crash happens trying to copy a file from one folder to another. After the crash, I have a grayed-out file in the folder I'm trying to copy to with a size of zero bytes. Trying to delete the file results in an error saying the file is in use.
It just so happens that I have run a Perl script on the same file a few steps before. Is it possible the reason for the crash is that Perl still has the file open? If so, is there a way to ensure that Perl is done before doing the copy? It shouldn't take very long as the file being worked on is less than 1000 bytes in size. If it's not Perl having the file open, any suggestions as to what it might be?
Here's a snippet of code from the script where the error is happening. The error occurs on the "duplicate file Index_file ..." statement in the try block. All of this is inside a Tell Application "Finder" block.
set MactoDOS to "'s/\\015/\\015\\012/g'"
set POSIXFileName to POSIX path of file Index_file
set cmd to "perl -i -pe " & MactoDOS & " \"" & POSIXFileName & "\""
do shell script (cmd)
-------------------------------------------------------------------------------------------------
set step to "Step 13"
set mess to step & " - Copy " & Index_file & " to " & f_MainFolder
TextLib's Message(mess, logfile)
try
duplicate file Index_file to folder f_MainFolder with replacing
on error the error_message number the error_number
set mess to "Error in " & step & ": " & the error_number & ". " & the error_message
TextLib's Message(mess, logfile)
my do_error(error_number, mess)
end try