Re: Excel2004, System Events & NSReceiverEvaluationScriptError
Re: Excel2004, System Events & NSReceiverEvaluationScriptError
- Subject: Re: Excel2004, System Events & NSReceiverEvaluationScriptError
- From: "Scott Babcock" <email@hidden>
- Date: Fri, 17 Dec 2004 16:55:18 -0800
- Thread-topic: Excel2004, System Events & NSReceiverEvaluationScriptError
The best way I've found to handle this sort of issue is to wait for the target UI element to appear or vanish:
----------------------------------------------------------------------
-- loop until the referenced element appears
on _until(uiElem)
repeat until exists uiElem
delay 0.1
end repeat
end _until
-- loop until the referenced element vanishes
on _while(uiElem)
repeat while exists uiElem
delay 0.1
end repeat
end _while
tell application "Microsoft Excel"
activate
-- block until activation is complete
calculate active sheet
-- create some content
set value of range "A1" to "foo"
end tell
tell application "System Events"
tell application process "Microsoft Excel"
keystroke "p" using command down
set saveAsButton to a reference to button "Save As PDFÉ" of UI element 4 of window "Print"
my _until(saveAsButton)
click saveAsButton
set saveButton to a reference to button "Save" of window "Save To File"
my _until(saveButton)
keystroke "d" using command down
keystroke "My Desired Worksheet"
click saveButton
set printDialog to a reference to window "Print"
my _while(printDialog)
say "printing complete"
end tell
end tell
----------------------------------------------------------------------
Using the 'exists' event, you can determine whether or not your target element exists. Because elements are specified by reference instead being pointed to directly, AppleScript doesn't try to resolve them to objects and you avoid the NSReceiverEvaluationScriptError issue.
The _until() and _while() handlers are pretty unsophisticated, having no mechanism to deal with the possibility that the target element never appears (or vanishes, as the case may be). They do demonstrate the concept of element verification, though.
The rule is, never use a blind delay when you have a more reliable way to determine whether or not the user interface is ready for the next action.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden