I have managed to integrating checkbox ticking in my scripts. But for the life of me, I cannot figure out the syntax for ticking a checkbox if is not already ticked. I’ve tried boolean but it always comes back with a message saying “missing value”.
Is there a preset value for a ticked or unticked checkbox that AppleScript understands?
It is easy enough to automate a click on as it, as a graphical object on a window, but get the script to intelligent understand the current state of the checkbox still eludes me.
I ran it so often that I may guarantee that it works.
I would not be surprised to learn that your checkbox is not an UI element of the window “Bounce” but belongs to a (container) UI element of this window.
Don’t forget that Apple give us a powerful tool named Accessibility Inspector available as :
If I run it while Numbers is running as it was written in the handler posted in my late message, the Inspector would display :
AXApplication
AXWindow:AXStandardWindow
AXScrollArea
AXCheckBox
If the checkbox really belongs to the main window as you assume in your message, the Inspector would display:
AXApplication
AXWindow:AXStandardWindow
AXCheckBox
Many thanks for that. While trying to convert this script for my case it would be great if you could explain a couple of things for me. I have been phenomenally under-slept so please bare with me if the questions are very pedestrian!
You create the variable ruleTitleAndLegend(titleMode, legendMode). In this particular case, what are the variables titleMode and legendMode refer to? Should I assume these are program-specific relating to Numbers?
What I do not understand is if checkbox values are 0 for not checked and 1 for checked (or vice versa - it doesn’t matter) why a simple IF rule is not enough?
Of course, you will have to change the name of the process according to your needs
and, if, as you wrote, the checkboxes are really in the main window you will have to drop the “of scroll area 3” part of the instructions
It will become :
# the beginning of your script
set titleMode to 1 # will check the title checkbox
set legendMode to 0 # will uncheck the legend checkbox
# xMode = 1 --> check the box
# xMode = 0 --> uncheck the box
tell application "System Events" to tell process "yourProcess"
set frontmost to true
name of checkbox of window 1 # instruction useful to get infos, useless in real life
--> {"name1", "name2", "name3"}
try
if value of checkbox 1 of window 1 is not titleMode then
click checkbox 1 of window 1 # rule Title
end if
end try
try
if value of checkbox 2 of window 1 is not legendMode then
click checkbox 2 of window 1 # rule Legend
end if
end try
end tell # application "System Events" to tell process "yourProcess"
# end of your script
If these explanations aren’t sufficient, it would be useful to tell - as I already asked - the way to get the used application so that me or an other helper try to see what is the wrongdoer.