[Pythonmac-SIG] Using appscript for GUI interaction, button click
has
hengist.podd at virgin.net
Sun Sep 13 19:52:05 CEST 2009
Charles Miller wrote:
> I'm trying to perform the following applescript with the appscript
> Python module:
>
> tell application "System Events"
> tell process "Preview" to click button "OK" of every window
> end tell
If you're not sure how to translate an AppleScript command to the
equivalent appscript syntax, ASTranslate is your friend:
app(u'System
Events').processes[u'Preview'].windows.buttons[u'OK'].click()
> import appscript
> appscript.app('System
> Events').processes['Preview'].windows[1].buttons[1].click()
>
> but I get the error:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "build/bdist.macosx-10.3-fat/egg/appscript/reference.py", line
> 492, in __call__
> appscript.reference.CommandError: Command failed:
> OSERROR: -609
> MESSAGE: Connection is invalid.
> COMMAND: app(u'/System/Library/CoreServices/System
> Events.app').processes['Preview'].windows[1].buttons[1].click()
Error -609 means either the target application unexpectedly quit while
handling the event, or the command didn't complete within the allotted
timeout period (which should be error -1712, but the Apple Event
Manager sometimes returns the wrong code). So does the original
AppleScript work? If not, the problem is in what you're trying to do.
If it does, then see if the ASTranslate-based translation works.
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
More information about the Pythonmac-SIG
mailing list