Applescript Checkbox help

Hi,

I am using Mac OS X (version 10.6.8), QuarkXpress 8.15 and Applescript Editor (version 2.3)

I have tried to check a checkbox in QuarkXpress Find/Change Palette with the below script. But I Can’t. Can anyone help me.

tell application "QuarkXPress" to activate -- with a Word document already open
tell application "System Events"
	--keystroke "p" using command down -- with the print window NOT already open
	tell process "QuarkXpress"
		delay 1
		set theCheckbox to checkbox "Layout" of window 1 of window "Find/Change"
		tell theCheckbox
			set checkboxStatus to value of theCheckbox as boolean
			if checkboxStatus is false then click theCheckbox
		end tell
		
	end tell
end tell

Thanks in advance

Hello

I don’t own QuarkXpress.

Are you sure that you are correctly defining the target object ?

You use :
set theCheckbox to checkbox “Layout” of window 1 of window “Find/Change”

“Find/Change” is the name of the floating window open by the menu item “Find/Change”.
As far as I know, it’s not supposed to own a subwindow.

In several applications it would be
set theCheckbox to checkbox “Layout” of window “Find/Change”

Yvan KOENIG (VALLAURIS, France) samedi 15 novembre 2014 15:05:37

Yes you’re right its an floating window. Its an find and replace Palette.

There are 5 Checkboxes in the palatte.

set theCheckbox to checkbox "Layout" of  window "Find/Change"

This one also not works.

My memory is unable to tell me if there is an application like “Accessibility Inspector” in Mac OS 10.6.8.
If there is, it’s in the Developer folder.
Run it to get the exact structure of the palette.
The checkbox may be an element of a group of UI elements.

If you don’t have this application, try to run this short script :

tell application "QuarkXPress" to activate -- with a Word document already open¨
tell application "System Events"
   tell process "QuarkXpress"
       delay 1
       class of UI elements of window "Find/Change"  
       -- name of UI elements of window "Find/Change"    
   end tell
end tell

It will give you the list of the UI elements available in the palette.
You will learn for sure if the checkbox is a first level UI element or if you must search it in a group.

Yvan KOENIG (VALLAURIS, France) samedi 15 novembre 2014 15:51:35

Its not working

I apologize but “It’s not working” give no useful information.
Which behavior are you getting ?

Here, when I clicked on “Open this script in your editor” I got extraneous characters at the beginning or/and at the end of several lines. When it refused to compile, the editor was polite enough to show the offending extraneous characters.
It was easy to remove them and get a compiled script.

I made tests with TextWrangler.

tell application "TextWrangler" to activate -- with a Word document already open¨
tell application "System Events"
	get name of every application process
	log result
	(*loginwindow, Script Editor, Numbers, Pages, Activity Monitor, Wacom Desktop Center, Dock, SystemUIServer, universalaccessd, AirPlayUIAgent, Finder, com.apple.internetaccounts, sharingd, com.apple.dock.extra, CoreServicesUIAgent, Spotlight, iTunesHelper, ASObjC Runner, FastScripts, TISwitcher, Keychain Circle Notification, Folder Actions Dispatcher, Shady, NotificationCenter, SMARTReporter, WacomTabletDriver, WacomTouchDriver, WiFiAgent, System Events, TabletDriver, storeuid, Safari, com.apple.WebKit.Networking, Mail, AppleSpell, com.apple.WebKit.WebContent, com.apple.MailServiceAgent, com.apple.WebKit.WebContent, com.apple.WebKit.WebContent, Preview, Image Capture Extension, TextWrangler*)
	tell process "TextWrangler"
		keystroke "f" using {command down}
		delay 1
		set windowName to "Find" # "Find/Change" for Quark Xpress
		class of UI elements of window windowName
		log result
		--> {static text, grow area, button, button, button, UI element}  
		class of UI elements of UI element -1 of window windowName
		log result
		--> {checkbox, checkbox, checkbox, checkbox, checkbox, UI element, UI element, button, button, button, button, button, button, scroll bar, scroll bar}
		name of UI elements of UI element -1 of window windowName
		-->{"Entire word", "Case sensitive", "Grep", "Wrap around", "Selected text only", missing value, missing value, "Replace & Find", "Replace All", "Replace", "Find All", "Previous", "Next", missing value, missing value}
	end tell
end tell

In this application, as I assumed in my late message, the text boxes are not at the root of the UI arborescence.
Worse, TextWrangler doesn’t put them in a group but in a “unknown structure”.
Happily, as you may see, triggering this structure as “UI element -1” gave access to the checkboxes.

As you may see, I added an instruction listing the available processes.
I did that so that you may check if the QuarkXpress process is really named “QuarkXpress”.
Some applications add some complementary infos at the end of their process’s name.
I also inserted an instruction opening the Find dialog to be sure that it will be available when the script will try to trigger it.
At last, I defined the window name in a variable so that a single change would be sufficient when switching from TextWrangled whose dialog is named “Find” to QuarkXpress which, according to what you wrote, name its dialog “Find/Replace”

So, to test under QuarkXpress, you may use :

tell application "QuarkXpress" to activate -- with a Word document already open¨
tell application "System Events"
	get name of every application process
	log result
	tell process "QuarkXpress"
		keystroke "f" using {command down}
		delay 1
		set windowName to "Find/Change"
		class of UI elements of window windowName
		log result 
		class of UI elements of UI element -1 of window windowName
		log result
		name of UI elements of UI element -1 of window windowName
	end tell
end tell

Of course, if this time there are again extraneous characters when you click “Open this script in your editor”.
Be patient and remove them carefully.
If it fails, check in the list of processes names that the correct one is really “QuarkXpress”. If it’s not, edit the script accordingly.
Of course, with QuarkXpress, if there is one, the structure hosting the check boxes may be at a different location in the list of first level UI elements.
Edit the instruction triggering it accordingly. Maybe QuarkXpress is fair enough to use an official group structure.

If at the very last it continue to fail, post the exact error message, not a useless “it’s not working”.

Yvan KOENIG (VALLAURIS, France) lundi 17 novembre 2014 10:30:27

I apologize for my last post…:frowning:
I tried your script. I Checked the process Name and Window Name. Both are correct. But its showing Can’t get process “QuarkXpress” error and highlighting the word class on the below line

class of UI elements of window windowName

AppleScript Editor’s Replies window shows as follows.

tell application "QuarkXPress"
	activate
end tell
tell application "System Events"
	get name of every application process
		--> {"loginwindow", "Dock", "SystemUIServer", "Finder", "SymSecondaryLaunch", "SymQuickMenu", "ScanNotification", "AirPort Base Station Agent", "ARDAgent", "Suitcase Fusion 4", "Distiller", "FMCore", "Safari", "AppleSpell", "firefox-bin", "Microsoft Excel", "Microsoft AU Daemon", "AppleScript Editor", "QuarkXPress", "jamfAgent", "TextWrangler", "Microsoft Word", "System Events"}
	(*loginwindow, Dock, SystemUIServer, Finder, SymSecondaryLaunch, SymQuickMenu, ScanNotification, AirPort Base Station Agent, ARDAgent, Suitcase Fusion 4, Distiller, FMCore, Safari, AppleSpell, firefox-bin, Microsoft Excel, Microsoft AU Daemon, AppleScript Editor, QuarkXPress, jamfAgent, TextWrangler, Microsoft Word, System Events*)
	keystroke "f" using {command down}
	get class of every UI element of window "Find/Change" of process "QuarkXpress"
		--> error number -1728 from «class prcs» "QuarkXpress"
Result:
error "System Events got an error: Can't get process \"QuarkXpress\"." number -1728 from process "QuarkXpress"

Maybe it’s important to say that dialog boxes like print and export dialogs in QuarkXPress are quite complex. Most interactive UI elements like buttons are only for presentation, the real responder is often an separate hidden UI element. When hovering over the button with an UI inspector tool will not give you the correct object that will respond to the click. Maybe it has something to do with QuarkXPress clever localization, multi platform support or both but the interfaces are not like normal Cocoa applications.

I think this information can save you some time.

UPDATE Does not apply for find and replace dialog in QuarkXPress 8 and 9.

To be sure of the window name, try :

tell application "QuarkXpress" to activate -- with a Word document already open¨
tell application "System Events"
	get name of every application process
	log result
	tell process "QuarkXpress"
		keystroke "f" using {command down}
		delay 1
		name of every window
	end tell
end tell

I may be wrong but, if the name is OK, I see only an explanation : QuarkXpress can’t be driven by GUIScripting.
It may be why I don’t remember any script doing that.

Yvan KOENIG (VALLAURIS, France) lundi 17 novembre 2014 11:58:19

PS :
I just see DJ Bazzie Wazzie’s message.
It let me think that QuarkXpress dialogs can’t be driven by GUIScripting.
I had the same problem with AppleWorks Print dialogs.

It seems I was wrong about the find/replace dialog, but my story still applies to print and export pdf dialog boxes. At least they are partly UI scriptable. You can’t change the state but you can click on them.


tell application "QuarkXPress" to activate
tell application "System Events"
	tell process "QuarkXPress"
		click UI element "Opmaak" of UI element "Zoek/Verander"
	end tell
end tell

I don’t know the English words exactly but I guess you’re looking for something like click UI element “Layout” of UI element “Find/Change”. The name of the UI element changes when you change the application language.

First I thank you all, who tried for me.

This script works Fine.

tell application "QuarkXPress" to activate
tell application "System Events"
	tell process "QuarkXPress"
		click UI element "Ignore Attributes" of UI element "Find/Change"
		--or
                --click checkbox 2 of UI element "Find/Change"
	end tell
end tell

Little bit I need, Only to Click if the checkbox is already checked. While unchecking “Ignore
Attributes” it is listing a list of checkboxes how to play with that.

Good news.

When the check box is checked, is it’s name the same than when it is unchecked ?
If it is, you may try to run (on a system where the checkbox in unchecked) :

tell application "QuarkXPress" to activate
tell application "System Events"
	tell process "QuarkXPress"
		# try to get informations about every UI elements available in the "window"
		get properties of UI element "Find/Change"
		log result --> list 1
		get properties of UI element "Ignore Attributes" of UI element "Find/Change"
		log result --> list 2
		click UI element "Ignore Attributes" of UI element "Find/Change"
		get properties of UI element "Ignore Attributes" of UI element "Find/Change"
		log result --> list 3
		--or
                --click checkbox 2 of UI element "Find/Change"
	end tell
end tell

I’m not sure that your code must be understood as : we may use click checkbox 2 of UI element “Find/Change”
so the list 1 will be useful to see exactly which/what is the UI element to trigger.
Compare list 2 to list 3 to see which property is modified when the box is checked.
If there is one, you will be able to check its value to decide if the script must click or must not.

Yvan KOENIG (VALLAURIS, France) lundi 17 novembre 2014 14:18:05

When I run your script, Its shows no changes. when I run the below script by checking and unchecking manually, I got the changes. The value is 0 when unchecked and 1 when checked.

tell application "QuarkXPress" to activate
tell application "System Events"
	tell process "QuarkXPress"
		get properties of UI element "Ignore Attributes" of UI element "Find/Change"
		log result --> list 2
	end tell
end tell

Replies windows result for your reference.

tell application "QuarkXPress"
	activate
end tell
tell application "System Events"
	get properties of UI element "Ignore Attributes" of UI element "Find/Change" of process "QuarkXPress"
		--> {minimum value:0, orientation:missing value, position:{1252, 592}, class:checkbox, role description:"check box", accessibility description:missing value, focused:false, title:"Ignore Attributes", size:{128, 16}, value:0, help:missing value, enabled:true, maximum value:2, role:"AXCheckBox", entire contents:{}, subrole:missing value, selected:missing value, name:"Ignore Attributes", description:"check box"}
	(*class:checkbox, minimum value:0, orientation:missing value, position:1252, 592, role description:check box, accessibility description:missing value, focused:false, title:Ignore Attributes, size:128, 16, value:0, help:missing value, enabled:true, maximum value:2, role:AXCheckBox, entire contents:, subrole:missing value, selected:missing value, name:Ignore Attributes, description:check box*)
end tell

value:0 when unchecked
value:1 when unchecked

click checkbox 2 of UI element "Find/Change"

The above line is also worked. As I have mention already there are 5 check boxes. It worked from Checkbox 1 to checkbox 5. The “Ignore Attributes” is checkbox 3

When I uncheck the “Ignore Attributes” checkbox manually, it was listing a list of checkboxes which was hidden in the palette, samelike when I check the checkbox it will hide the list of checkboxes. whereas when I uncheck the Checkbox by using the script. Its just unchecking the tick mark, and the list of checkboxes are not shown.
What may be the problem?

I apologizes if I ask details but English is not my language so I am not sure to understand well.

At this time my understanding is that if the checkbox “Ignore Attributes” is unchecked, its value is 0 and some other checkboxes aren’t displayed.
If the box is checked, its value is also 0 and the other boxes are hidden.

I assume that the script clicked the box but that as written by DJ Bazzie Wazzie the app doesn’t respond perfectly to GUIScripting.
Sometimes an instruction like :
perform action xxxx
may do the job but alas, I don’t know the list of actions available.

As I am curious, I ask you to try to re-issue the instruction
keystroke “f” using {command down}
after clicking the box by script. Maybe it will be able to reveal the checkboxes.

set theApp to "QuarkXpress"
set dialogName to "Find/Change"
set boxName to "Ignore Attributes"

tell application theApp to activate
tell application "System Events"
	tell process theApp
		keystroke "f" using {command down}
		set theValue to get value of checkbox boxName of UI element dialogName
		log thevalue
		click checkbox boxName of UI element dialogName
		delay .1
		set theValue to get value of checkbox boxName of UI element dialogName
		log thevalue
		keystroke "f" using {command down}
		set theValue to get value of checkbox boxName of UI element dialogName
		log thevalue
		end tell
end tell

I used variables to define three items because I tested the script upon an other application.

Yvan KOENIG (VALLAURIS, France) mardi 18 novembre 2014 10:32:41

Like you English is not my language. So I apologize, If anywhere I am not explained clear.

I think It will be clear now.
Floating window contains 5 checkboxes in active (for eg., Floating Box Height is 5 cm.)
I we uncheck “Ignore Attributes” an addition of 15 Checkboxes (total 20) shown in the same floating window by expanding the height to 20 cm. (Just like - pressing option button in some application floating window.)
If “Ignore Attributes” in checked its value is 1 and if unchecked the value is 0.

How to use perform action xxxx?

I tried your last script.

It shows the error in Replies Window as follows

tell application "QuarkXPress"
	activate
end tell
tell application "System Events"
	keystroke "f" using {command down}
	get value of checkbox "Ignore Attributes" of UI element "Find/Change" of process "QuarkXpress"
		--> error number -1728 from «class prcs» "QuarkXpress"
Result:
error "System Events got an error: Can't get process \"QuarkXpress\"." number -1728 from process "QuarkXpress"

The same way as in my click example…

tell application "QuarkXPress" to activate
tell application "System Events"
	tell process "QuarkXPress"
		perform action "AXPress" of UI element "Ignore Attributes" of UI element "Find/Change"
	end tell
end tell

I tried this

tell application "QuarkXPress" to activate
tell application "System Events"
	tell process "QuarkXPress"
		if (value of UI element "Ignore Attributes" of UI element "Find/Change") is 1 then
			--click UI element "Ignore Attributes" of UI element "Find/Change"
			perform action "AXPress" of UI element "Ignore Attributes" of UI element "Find/Change"
		end if
	end tell
end tell

This one also just unchecking the tick mark of “Ignore Attributes”

Try what I wrote in my late message :

tell application "QuarkXPress" to activate
tell application "System Events"
   tell process "QuarkXPress"
       if (value of UI element "Ignore Attributes" of UI element "Find/Change") is 1 then
           --click UI element "Ignore Attributes" of UI element "Find/Change"
           perform action "AXPress" of UI element "Ignore Attributes" of UI element "Find/Change"
delay .2 # let the app receive the action
keystroke "f" using {command down} # Try to force the app to rebuild its dialog
       end if
   end tell
end tell

Maybe this will force the app to fully update its dialog.

Yvan KOENIG (VALLAURIS, France) mardi 18 novembre 2014 18:16:08

PS
A big thanks to DJ Bazzie Wazzie for the name of the action.

Hi Yvan Koenig,

I tried your last post. Its shows error as below.

tell application "QuarkXPress"
	activate
end tell
tell application "System Events"
	keystroke "f" using {command down}
	get value of checkbox "Ignore Attributes" of UI element "Find/Change" of process "QuarkXpress"
		--> error number -1728 from «class prcs» "QuarkXpress"
Result:
error "System Events got an error: Can't get process \"QuarkXpress\"." number -1728 from process "QuarkXpress"

And I tried your latest post.

It just unchecking the tick mark of “Ignore Attributes”

If perform action works for some application. Then why its not working for quark.

#1
I never wrote such instruction :
get value of checkbox “Ignore Attributes” of UI element “Find/Change” of process “QuarkXpress”
Look back to my late script trying to trigger an element thru its class : checkbox.
It was in message #14.
My understanding is that the error message doesn’t match the reality.
The script perfectly reached the process QuarkXpress.
It just failed to recognize the object defined by checkbox “Ignore Attributes”
When I made tests with TextWrangler, I got the same error code when I wrote ” deliberately ” just for see :
get value of checkbox “Ignore Attributes” but this time it was accurate : there is no such box in TextWrangler’s dialog.

#2
As it appeared that QuarkXpress is unable to behave the standard way, I rewrote the code so that it tried to trigger UI element “Ignore Attributes”.
It’s boring but it’s consistent with what we discovered before :
QuarkXpress is unable to recognize window “Find/Change” but it recognizes UI element “Find/Change” .
I’m quite sure that if we urge it to return the properties of this UI element it will state that its class is : window (or floating window) as it returns class : checkbox when we ask it for properties of the UI element “Ignore Attributes”

#3
QuarkXpress play the game without applying the rules defined by Apple.
I’m quite sure that the product would be rejected if the editor tried to distribute it on mac App Store.
The rules were not defined to allow us to drive the applications with GUIScripting.
They were defined with accessibility concern. GUIScripting is just taking benefit of this major concern. Remember how we were activating it :
checking the checkbox : enable assistive device.
Alas, this concern doesn’t matter for QuarkXpress guys which just coded looking the end of their nose.
I guess that there is no hope to make them understand that and so, we will be unable to drive seriously them with GUIScripting.
Sometimes my first idea is to use GUIScripting to execute a given task and somebody post a cleaner script using standard AppleScript.
As I don’t own Xpress, I can’t say if there is an alternate way to achieve your goal.
I just remember how fast users dropped Xpress when they discovered that inDesign was offering a better AppleScript support.

Yvan KOENIG (VALLAURIS, France) mercredi 19 novembre 2014 16:14:53