An issue I keep running into in my Scripts is that Applescript seems to always run things as fast as possible, not waiting on previous events to complete.
For instance, I tell Finder to eject a Sparse disk image on a USB external drive, then to eject the USB drive. When I do that, I get an error that the drive is still in use. But if I put a delay in between, all is well.
In Cheeseman’s article on running parallel actions by using ignore application responses, he implies that, unless this is used, things occur seqentially.
Is what I am seeing is that Finder is saying it has completed its task of telling the SDI to eject, and so it is finished, even though some other application (say, SDI helper) is still working?
In the scripts I have written so far, I have lots of delay commands to cope with this issue, is there a better way?
Here is my specific script, and any other critiques are welcome.
tell application "Finder"
close every window
open application file "Quit Everything.app" of folder "Applications" of startup disk
end tell
delay 10
display dialog "Did Everything Quit?
If not, finish closing them and press OK"
display dialog "Eject Unused Volumes"
display dialog "If needed,
Connect LaCie Portable Hard Drive.
Wait for it to be mounted."
tell application "Finder"
make new Finder window
open document file "PortBU.sparseimage" of disk "Portable BU"
delay 5
close every window
end tell
tell application "SuperDuper!"
run using settings "Smart Update PortBU.sdsp" without user interaction
end tell
delay 5
repeat
tell application "Finder"
if process "superduper!" exists then
delay 5
else
exit repeat
end if
end tell
end repeat
tell application "Finder"
eject "PortBU"
delay 5
eject "Portable BU"
end tell
display dialog "Remove LaCie Portable Hard Drive
Then Mac mini will re-start"
tell application "System Events" to restart
David