Inconsistent window index # in app with one window

Greetings all! This is my first post. I am new to applescript, have seen some snippets of code here and there in the past, but have never really scripted with it before. I am working on a project for a client which involves a very misbehaving and non-conforming app. Basically, what we are trying to do is perform a series of actions when a certain key is pressed. I am attempting to use UI scripting to get the job done - and had succeeded at one point. Unfortunately, the app is causing a lot of problems - namely the window indexes are not consistent. To top it off, the end of title of the main (and only) window changes when a different feature of the app is selected.

To help further explain my problem, here is my code:

if title of window "19" contains "Oranges" then
   perform action "AXIncrement" of slider 3 of scroll area 1 of window 8
else if title of window "19" contains "Apples" then
   click button 4 of scroll area 1 of window 4
end if

The problem is that not just the main window, but it seems like all the windows - change their index #'s. (In the example above, the “main” window is window “19” - that’s just the value it happened to be at the time). The index #'s change, but the location of elements are consistent. The main window also changes title based on function, so I can’t just use the full name of the window either. However, it’s only the end of the window title that changes, not the whole thing. So you have “Application XYZ - Oranges” if you’re in that mode, then you have “Application XYZ - Apples” if you’re in that mode.

Edit: Heh, spent so much time describing my problem, I forgot to ask my question. How can I ensure the same buttons I want to press are selected, regardless of window index # or name?

Thanks for any advice you can provide.

Model: mac mini
AppleScript: 2.0
Browser: Safari 523.15
Operating System: Mac OS X (10.5)

Okay I think I followed your dilemma, but I don’t quite think I followed your question. Say again?

Also what is the actual app you are using? Perhaps someone else has it as well and could better help.

Hello James! Thanks for the response. I know I have a bad habit of making things seem more complex than they should be - so thanks for bearing with me.

Unfortunately, I am bound by an NDA so I can’t disclose the actual app - needless to say this app returns “AXwindow:AXunknown” for virtually all windows other than the main window in the UI Browser. This app has one main window, which in UI Browser is described as “standard window” and I also noticed the attribute “main” is set to true. So if this is a way to locate the main window in an app, that would be great! I just don’t know how to do it.

Within this main window are mini-windows, that perform different functions, hold sliders and buttons and scroll bars and so on. That’s where all these “AXwindow:AXunknown” windows come from.

Let me try to rephrase my question - in an application whose window indexes constantly changes, how can I refer to a particular button within this app?

It needs to be the same button every time, and I can’t depend on “move mouse to x,y co-ordinates” as the user may resize the window, etc. Since I’d like to ensure with a decent amount of confidence it’s the same button selected each time, I’m hoping to do this thru UI Scripting with AppleScript.

This wouldn’t do it consistently:
perform action “AXIncrement” of slider 3 of scroll area 1 of window 8
because the value of the window index changes.

Note it does work and do what I want it to do if you input the correct value to the window index.

Thanks for any additional help you could provide.

I think I got this to work reliably! :slight_smile:

tell application "System Events"
	tell process "MyApp"
		set badWindow to name of first window whose name contains "MyApp"
end tell
end tell

badWindow now returns a consistent reference to the frontmost window, which I can then use to access other UI elements within that window.

I hope this helps anyone else out that is having a similar problem to what I was having.

THe next step will be getting consistent references to either the windows within this main window, or straight to the actual button in question (if possible). The former is going to be much, much harder than the script above, because all of the subwindows have no name, and their index changes (they are all “AXwindow:AXunknown”). The later might be do-able by utilizing the “help” attribute of the button I want. Since the buttons have no “name” attribute", can’t search for them that way, but they all have a “help” attribute which pops up if you hold the mouse over the button in question. I figure if I can somehow locate this unique piece of text, then I could refer to the parent to get the button I want. I really have no idea how to do this at this point, so it’s going to be another fun journey! Of course, if anyone has any ideas or thoughts I would greatly appreciate any help you can provide.