Help with UI click scripting

I need to click on tab items that come up in a print sub menu.

There are three tabs and they show up in UI Browser as:
UI element 1 of UI element 5 of UI element 2 of window “Print Setup”
UI element 2 of " "
UI element 3 of “”

the following doesn’t work:
tell application “System Events”
Click UI element 1 of UI element 5 of UI eleement 2 of window “Print Setup”
end tell

I don’t no if there is a speacial command for clicking tabs or is there a problem because UI says these are elements not buttons?

I also tried to have the scrip query the position of the button I wanted to click and then issue a coordinate click in the window that these tabs are in. This isn’t working but I haven’t been able to get coordinate mouse clicks to work at all, let alone this window.

The script was as follows
tell application “System Events”
set clickPos to position of UI element 2 of UI element 5 of UI element 2 of window “Print Setup”
click “Print Setup” at clickPos
end tell

Now I know that it is clicking at the appropriate position because I tested the script output against the button location I got from the app “Pixie”

What am I doing wrong?

What application are you trying to do this in and what version of OS X are you running. I thought you were referring to Printer Setup Utility but couldn’t find anything you mention there, then I noticed you said it was a sub-menu, etc.

Where exactly is the problem happening with what app (e.g., how would you do what you want to do by hand)? That should make it a little easier to help you find an answer.

I am trying to set the advanced features (filename, crop marks, page size) on Freehand MX.

You used to be able to print with filename by issuing the commands
Tell application Freehand 9
print with filename
end tell

Now freehand ignores the extra print commands and just brings up the print menu and stalls there waiting for user input.

So I have been UI scripting freehand. I have been able to get it to batch print a group of files but whether or not it prints a file name in the upper left corner is left to the mercy of how the file was last printed.

To get to the Advanced features, you have to press a popup dialog and select the menu item Freehand in the print window. Once you have done this you can click the button “Advanced”. This is all done inside the menu “Print”. Once you click advanced it opens a new window called “Print Setup” this is where the three tabs lie that I have to set the options. Consequently which of the three tabs are brought to the front is left to the mercy of which one was last clicked on last time a file was printed out of freehand. There are no keyboard functions or tab functions that work in this menu, so using keyborad commands is out of the question. I am able to script the options in the tabs just fine. I just can’t make the tabs switch as needed. All the steps leading up to bringing up the “Print Setup” window are completed. I just cannot make a mouse click or make a UI selection of the Tabs themselves.

Not sure if you’re using Freehand MX 2004, but if you are, it’s dictionary includes the “with filename” type functionality, but the wording has changed…it’s now “with PrintFileName”. Try this:

[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hope this helps.

I am using Freehand MX 11.0 for OS X. I checked macromedia’s website and they do not offer a product know as Freehand MX 2004, Only Freehand MX. Now I do see this in the dictionary, however when I use this command it simply brings up the print dialog and stops, which is why I have to use the UI scripting to press the print button. Do you have this working with freehand MX 11.0 or possibly 11.0.2?

Yep, it’s 11.0.2. I got it as part of the Macromedia Studio 2004 suite so I guess they labeled the folder “Freehand MX 2004”, sorry for the confusion.

I hadn’t actually tried the script, I just saw it and thought it would work. I was obviously wrong since I’ve tried it just now. I also noticed a “UsingDialog” option for the “print” command in Freehand but that doesn’t seem to do anything either…

I tried to get to the “Advanced” section of the Print dialog you referred to. I followed your instructions, selected “Print” from the File menu. Then selected “Freehand MX” from the pull down menu in the print dialog. And then clicked the “Advanced” button that appeared. However, all it did was give me a print preview. I don’t use Freehand so I’ve never tried to print from it etc. but I’m assuming that something’s not working right on my end. I wanted to say it could be Printer dependent but in thinking about the option were talking about (pring with file name) I can’t really see how that would be available on somoe printers but not others. I’m at a loss.

Suprisingly, the advanced menu is printer specific. This may be because of faulty drivers for local or USB printers or it just may only be supported on true PS printers. If you build a local IP printer to for say a Laserjet 4000 or 4550, and print to that then all the advance menus appear when you click advanced. I’ve noticed that the advance menu only shows the preview you mention for injet printers like my USB Lexmark 43 at home.

That explains it. I don’t really do any “professional” graphics work so I have no need to fork out the cash for a PS printer. I wish I could offer more help but it looks like you’ve already tried using “UI Elmenet Inspector” to try to taget the correct tab. One thing you may try, fire up UI Element Inspector, Get the Prinnter Setup/Advanced dialog to pop up, lock on the tab you want using cmd-F10. In the UI Element Inspector “locked target” (?) window (the new one that appears when you lock onto an element), at the bottom, will be a pull-down menu that lists all of the actions that can be performed on the item. If it says AXPress then that’s the same as “click”. Select the approprate one from the pull-down menu and then click the “Perform” button to see if that switches tab views as expected. If it does, then there’s probably a scripting error in targeting the tab. If it doesn’t work, then you may be out of luck. GUI Scripting isn’t perfect and there are a number of places where it just doesn’t work (like clicking the “Show Genre When Browsing” checkbox in iTunes Prefs).

Good luck

Cool trick, Thanks
-UI Element Inspector shows no actions for those tabs.
-Can you not just have the GUI click on coordinates to simulate a click in that area in order to simulate a click on the tab?
I now that I can have applescript find the coordinates of the tab that I want to click but passing a click via [ click {123, 210}] doesn’t force a mouse click at those coordinates. Does Coordinate clicking function globally, or is its function limited to App specific situations as well as more specific click actions?

This follow-up is for future FHMX scripters looking for answers to the same issue.

I have spent hours trying to get FreeHand’s print menus and commands to work. This is what I have found:

Essentially, AS printing is kinda broke for FreeHand MX!

Using the “print” commands from the FreeHand dictionary is useless for FHMX. All you get is the print dialog window. You can press return to begin printing but no settings are applied. Using any other command with print (eg. Copies, SettingsFile, UsingDialog etc) makes no difference to the printed result.

You’re better off with UI scripting.

All elements of the FreeHand print windows can be UI scripted with the following exceptions. The Print Setup window tabs (in Advanced) for “Separations”, “Imaging” and “Paper Setup” cannot be clicked. I’ve tried using UI Browser to locate them but there is no AXPress action for these tabs (seen as unknown 1, 2 & 3) and location clicking just doesn’t work.

The only workaround I have is to get the script to request the user to click the various tabs - not elegant but it works. This is achieved by having the script look for a unique element from within each tab and try to get a value from it. If it returns an error (ie. the wrong tab is selected and therefore the element can’t be found) the computer says “Please click on the XXX tab” every few seconds. When the tab is finally selected and the value for the element can be obtained the rest of the UI scripting for that tab kicks in. This is an unfortunate interruption to the script but it may be worth the effort to someone.

Here’s a sample code of what I just described (for OSX10.4)

tell application "System Events"
	tell process "FreeHand MX"
			if (exists checkbox "Transverse" of UI element 1 of UI element 2 of window "Print Setup") then
				exit repeat
				beep 3
				say "Please select the Paper Setup tab." using "Vicki"
				delay 3
			end if
		end repeat
	end tell
end tell
-- continue on UI scripting the elements for that tab 

To simplify the UI scripting requirements you can set up FH Print Settings and have the script select the desired print setting. The Print Settings file seems to change all the dialog settings except for paper size when the document has been previously printed with the “Custom” paper setting. If, say, an A4 Print Setting is called (has A4 as the paper size) the doc will still print as Custom. So, UI scripting this bit may be a requirement if you’re likely to run into this trouble. We have this scenario pop up in our studio because the designers print to PDF for each client approval stage when they print a custom paper size PDF.

I’m suspecting that these issues won’t be fixed for a long while or at all (depending on what Adobe has in mind for FreeHand in the future). So this is all we have to work with for now unless someone else has a miracle solution.