I've found another problem in Mt Lion (10.8.2) that deserves mention.
(But, has nothing to do with GUI scripting.)
My script writes a message as a pdf file to the desktop, then …
set tempPrintFolder to (path to desktop)
tell application "Finder"
activate
repeat 50 times -- wait for file to appear
if (exists file tempFileName of tempPrintFolder) then exit repeat
delay 0.1
end repeat
if not (exists file tempFileName of tempPrintFolder) then error "The pdf document was not created."
set pdfTempDoc to (file tempFileName of tempPrintFolder) as alias
set pdfDocAlias to (duplicate pdfTempDoc to destinationFolder with replacing) as alias
The problem I encountered was a duplicate file that was unreadable/un-openable in Preview.
In other words, the file was corrupted.
The fix was to add a 'delay 1' ...
set tempPrintFolder to (path to desktop)
tell application "Finder"
activate
repeat 50 times -- wait for file to appear
if (exists file tempFileName of tempPrintFolder) then exit repeat
delay 0.1
end repeat
if not (exists file tempFileName of tempPrintFolder) then error "The pdf document was not created."
set pdfTempDoc to (file tempFileName of tempPrintFolder) as alias
delay 1 -- wait for file tempFileName to complete writing <<<<<<<<<<<<<<<<<<<< ADDED
set pdfDocAlias to (duplicate pdfTempDoc to destinationFolder with replacing) as alias
This bothers me. The file exists at the end of the repeat loop, but it has not finished writing.
I've never encountered this problem in Lion or previous systems. It seems to me that Mt Lion
should not make the file available for reading until it has finished writing.