• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
File not ready for reading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

File not ready for reading


  • Subject: File not ready for reading
  • From: Luther Fuller <email@hidden>
  • Date: Tue, 12 Mar 2013 11:11:36 -0500

While discussing the thread "Mail GUI script error", I wrote:

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.
(This would seem to me to be standard procedure in any OS !)

Yesterday and today, I was able to get back to this problem. The script I tested as a solution is …

tell application "Finder"
activate
repeat 50 times -- wait for file to appear
if (exists file (tempFileName & ".pdf") of tempPrintFolder) then exit repeat
delay 0.1
end repeat
if not (exists file (tempFileName & ".pdf") of tempPrintFolder) then error "The pdf document was not created."
set pdfTempDoc to (file (tempFileName & ".pdf") of tempPrintFolder) as alias


set diagCount to 0 --***************************
set fileSize to (size of pdfTempDoc)
repeat 100 times
delay 0.1
set diagCount to (diagCount + 1) --************************
size of pdfTempDoc
if fileSize < the result then
set fileSize to the result
else
exit repeat
end if
end repeat


set pdfDocAlias to (duplicate pdfTempDoc to destinationFolder with replacing) as alias

.
.
.


display dialog "diagnosticCount = " & diagCount --*************************
end tell

In Lion, this script always shows a diagnosticCount = 1 , indicating that the file has completed writing BEFORE it is available for reading.

In Mt Lion, this script shows a diagnosticCount = 2, 3 or 4 , indicating that the file was being written AFTER the file is available for reading.

The procedure in Lion is standard for any OS. The results for Mt Lion indicate that a serious bug has been introduced into the OS.

This brings to mind a variation on a theme of a monkey at a typewriter. Could a monkey at a typewriter, given a copy of Shakespeare's Hamlet, edit it and would it be an improvement?

I think I will wait for the release of 10.8.3 before testing again. Perhaps some of the flakiness in 10.8.2 will be fixed.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: File not ready for reading
      • From: Luther Fuller <email@hidden>
  • Prev by Date: Re: Slow app with Fusion drive.
  • Next by Date: Re: Slow app with Fusion drive.
  • Previous by thread: Re: In praise of Satimage
  • Next by thread: Re: File not ready for reading
  • Index(es):
    • Date
    • Thread