I really really want to be able to use GUI scripting. (I’m sure I’m not alone here, either.)
The big problem, is that where as some items can be selected (menu bar items, for example) window element actions don’t take effect.
For example: I can go to the main menu option titled Object > Rasterize… without any problems. I can even keystroke return that window so it goes away… But I want to be able to check or uncheck the radio boxes and check boxes in that window! I can’t even get the “OK” button to be clicked by calling it by name!
Wait, there’s something I need to clarify. Here’s the devil of the problem: I can get these elements to “flash blue”, as if they’ve been clicked very quickly. Using UI Inspector and the trial of UI Browser, I can call them by name and get a small reaction out of them. But nothing happens as a result! No boxes become checked or unchecked. No button clicks take effect!!! What the deuce is going on here? Are the A/S developers getting a chuckle at our expense?
The following is simply an example that pertains to one task I intend to script. (Please don’t suggest other ways of rasterizing unless the method is as global as UI scripting. Rasterizing is not the point, GUI scripting is.)
For this example to work, just create an Illustrator document with something(s) on the page. You’ll see it do it’s thing, open the window, then the check box will flash, then nothing will happen!
tell application "Illustrator CS"
activate
tell application "System Events"
tell process "Illustrator CS"
if not (exists window "Rasterize") then
delay 1
keystroke "a" using {command down}
delay 1
click menu item "Rasterize..." of menu "Object" of menu bar 1
end if
delay 2
click checkbox "Create Clipping Mask" of window "Rasterize"
end tell
end tell
end tell
I’m a little skeptical about GUI clicking instead of finding a way for GUI scripting to work. Telling a button to be clicked seems more reliable than telling a mouse to click at a specific point. Also, what if my user wants to use the mouse for other work while the script is running in a separate program?
How reliable has GUI clicking been for you?
Do the windows always show up in the same place?
What if you change monitors? Computers? Users?
Are there certain circumstances that it’s most reliable, and how do I create this situation?
Most elements can be selected by tabbing between elements. So once a window opens that you want to script, press tab until you get to the element and then press the space bar to check/uncheck it. Of course tabs and spaces can be scripted using keystroke commands once you figure out the number of tabs you need etc.
That won’t work. GUI scripting is all about the application you’re scripting being the frontmost application.
Sorry, I don’t have Illustrator so I can’t help with that. In order for the tabbing to work you need “Enable access for assistive devices” selected in the Universal Access preference pane… so you can check on that.
I know mouse clicks are not ideal compared to a scriptable
app but for that matter, neither is GUI.
This script should work regardless of screen resolution, user or monitor.
Move the Rasterize window around and then run the script. It always
finds the check box. (Tested on AI CS3 running Leopard 10.5.1)
You can download Extra Suites at no charge to test this out.
It pops up a little window on your screen asking you to purchase
but it functions normally otherwise.
I think this will do ok for you because the mouse click is
fast and there is only one and not a series of clicks so the
user should not be interrupted by the operation.
To answer your previous question, I have had great success
using mouse clicks. I have one stand-alone machine that runs
scripts throughout the day that uses mouse clicks. So far no
issues at all on that machine and it has been running like that
for nearly a year. I also use it on my machine mainly to automate
QuickBooks (which is completely non-scriptable,) but also anytime
an application or AppleScript falls short.
Since I use several apps that are AppleScript deficient I have
set up a library of mouse functions to facilitate the ease of
their use.
I hope this helps. Let me know how it goes.
Cheers!
Craig
activate application "Adobe Illustrator"
tell application "System Events"
tell process "Adobe Illustrator CS3"
--This will get position no matter where the window
--is or what the screen resolution is
try
tell checkbox "Create Clipping Mask" of window "Rasterize"
set {xPosition, yPosition} to position
set {xSize, ySize} to size
end tell
-- modify offsets if hot spot is not centered:
set click_pos to {xPosition + (xSize div 2), yPosition + (ySize div 2)}
--click chk box
my mouseClick(click_pos, 0)
end try
end tell
end tell
on mouseClick(move_to_and_click, the_delay)
tell application "Extra Suites"
ES move mouse move_to_and_click
ES click mouse
delay the_delay
end tell
end mouseClick
Thank you very much for not only answering my questions regarding the value of using “mouse scripting” but to also provide me with a great starter script for jumping right in!
(I’m running 10.4.11, not 10.5.1, but don’t foresee that being an issue.)