I’m writing a script that does the following
-
Use the open-source wpd2odt executable to convert an old WordPerfect file to Open Document format and save the output in the Temporary Items folder.
-
Use a tiny viewer app that I put together in Xcode to open a read-only TextView window which displays the converted ODT file (like a read-only TextEdit). The script launches this viewer app with an "open " command and the name of the converted file as an “–args” argument.
What baffles me is that the script sometimes needs to have delay of 1 to 3 seconds between converting the file and opening it in the application - if I don’t have the delay, the viewer application sometimes opens with a blank file. This seems to be intermittent; sometimes the script works without a delay; then, using the same input file, it works only if I add a 1-3 second delay.
My ignorant guess is that the output file is still busy when I try to open it, but I don’t see how this happen, since the wpd2odt command has to exit (I think) before the next command in the script can take place.
As an experiment, I’ve tried putting this code between the conversion command and the viewer application, but it never displays the dialogs:
set wpAlias to (POSIX file wpSource) as alias
tell application "System Events"
if busy status of wpAlias is true then
display dialog "Source busy"
end if
end tell
set odtAlias to (POSIX file odtOutput) as alias
tell application "System Events"
if busy status of odtAlias is true then
display dialog "Target busy"
end if
end tell
Am I missing something very obvious?