I have gone through stack overflow, this might seem like a duplicate question but this is more like an extended question to the existing issue!
I am facing a very strange issue, in my application we have customised the pop up button (Inheriting from NSPopupButton). When I use Apple Script to access the pop up item, the script is not able to select any value from the popup list.
Let me be more clear!
For eg. Imagine the Popup button has "Car, Bike, Cycle, Bus" as its items. Now if I use AppleScript to select Bike and then click enter, the value is not getting reflected. But manually if I select "Bike" it will reflect in the application. This is the script that I wrote.
click menu button "Car" of window 1 of application process "My Sample Application" of application "System Events"
key code 125 //I am using these to navigate down the list
delay 1
key code 125 //I am using these to navigate down the list
delay 1
key code 125 //I am using these to navigate down the list
delay 3
key code 36 //This line simulated ENTER/Return key (or NOT?)
I have also tried running this command in Apple Script
--set xxx to value of every button of menu button "Car" of window 1 of application process "LG Calibration Studio" of application "System Events"
This command was suppose to show me all the items present in the Popup, but unfortunately it is returning an empty array(or Dictionary). Even though the pop up is populated with values I am not sure why this is returning empty.
I am kind of new to Apple Script and do not have much knowledge in this domain. Any help is appreciated. Thanks in advance :)
When using UI scripting, the relationships between ui objects is not always clear. I'll use Apple's Pages (as it's freely available — I use an untouched 'Essay' document) as an example. Here are two suggestions to explore. If they make sense, you can try similar actions with your own app.
UI Elements command
In a new script…
Partial result of command 1
Partial result of command 2
Partial result of command 3
Using
ui elementsyou can work your way through the myriad interface objects in your window. You can also ask for specific properties, e.g.name of every pop up button. Finally, you can get a list of all ui elements withentire contents.Accessibility Inspector
Using the application Accessibility Inspector, you can inspect the window and discover its elements. This is located inside XCode's app bundle and is also accessible through the XCode > Open Developer Tool menu.
It changes with the version of XCode so there isn't any point in getting too detailed (I'm on Xcode 9) but once it is launched, click on the 'All Processes' drop down button at the top left and it should list the open apps; select Pages from this list.
A couple of things to note: At the bottom is the hierarchy of elements which can help in determining which object to act upon. Each line's bracketed text references the class of object but the text isn't always literal (e.g. your script should use 'window' not 'standard window').
If you use the 'pointer' and then in Pages, click on the empty area at the bottom of the Format inspector, the hierarchy will show a long list of items under (scroll area). Also, there are various ways to interact with an interface object, of which 'click' is but one.
If I insert this code into the script and then select the body text, the script will format the selection as italics (which matches the hierarchy entry 'Regular (pop up button)', with 'Regular' being the selection's existing font format.
Hopefully, utilizing these two approaches may yield some useful results before the onset of ui scripting headache.