Selecting “background” app menu bar menu items

I have an app (xBack) that is only accessible via a menu that lives in the right half of the menu bar, along with various “SystemUIServer” menus, like the Keyboard Layout menu.

However it does not have the attribute “AXDescription” that is called with the (incredible!) script work provided at page:

http://bbs.macscripter.net/viewtopic.php?id=18620 (thank you, Yvan and Kai!!)

The Accessibility Inspector reveals the following for the “Stop” menu item:

----
<AXApplication: “xBack”>
<AXButton: “”>

<AXMenuItem: “Stop”>

Attributes:
AXRole: “AXMenuItem”
AXRoleDescription: “menu item”
AXParent: “”
AXEnabled: “true”
AXPosition: “x=985 y=45”
AXSize: “w=242 h=19”
AXTitle: “Stop”
AXHelp: “(null)”
AXSelected (W): “true”
AXMenuItemCmdChar: “(null)”
AXMenuItemCmdVirtualKey: “(null)”
AXMenuItemCmdGlyph: “(null)”
AXMenuItemCmdModifiers: “0”
AXMenuItemMarkChar: "
AXMenuItemPrimaryUIElement: “(null)”

Actions:
AXCancel - cancel
AXPress - press
----

and the following is for the “Start” menu item:

----
<AXApplication: “xBack”>
<AXButton: “”>

<AXMenuItem: “Start”>

Attributes:
AXRole: “AXMenuItem”
AXRoleDescription: “menu item”
AXParent: “”
AXEnabled: “true”
AXPosition: “x=985 y=26”
AXSize: “w=242 h=19”
AXTitle: “Start”
AXHelp: “(null)”
AXSelected (W): “true”
AXMenuItemCmdChar: “(null)”
AXMenuItemCmdVirtualKey: “(null)”
AXMenuItemCmdGlyph: “(null)”
AXMenuItemCmdModifiers: “0”
AXMenuItemMarkChar: "
AXMenuItemPrimaryUIElement: “(null)”

Actions:
AXCancel - cancel
AXPress - press
----

I need a script to be able to select one or the other of these two menu items (which also, as you can see, are not in the same place in the menu items list). The xBack menu item moves around in the menu bar, depending on the apps that are running, so I can’t just issue mouse clicks according to a set of screen coordinates and I haven’t been able to figure out how to utilize the AXApplication and the AXMenuItem properties or the AXTitle attribute.

Thoughts?

Thanks!!

P.S. Also, the script attached to the link in posted scripts:

“Open this Scriplet in your Editor:”

used to work, but now strips out all the line breaks. Is that because I am still running 10.4.11? Thanks!

Model: MBP C2D
AppleScript: 1.10.7
Browser: Firefox 3.0.3
Operating System: Mac OS X (10.4)

Hi,

if you don’t have an unique description of the menu, there are three options:

¢ find another attribute to identify the menu definitely
¢ put the menu to a position which will never change
¢ walk thru the menus with GUI scripting to find the proper one.

Thank you, Stefan, for your suggestions on trying to call a menu item of a “button” that is placed in the menu bar by an app! Please allow me to ask for clarification. You stated:

If you don’t have an unique description of the menu, there are three options:
¢ find another attribute to identify the menu definitely

Given the results of the Accessibility Inspector that I posted above, does a “unique description of the menu” exist that can be addressed, and if so, how? The app “SystemUIServer” is not involved. My attempts so far have been unsuccessful. Is there any such “another attribute to identify the menu definitely”?

¢ put the menu to a position which will never change

Unfortunately, as I mention above, this is not an option, but I appreciate the suggestion!

¢ walk thru the menus with GUI scripting to find the proper one.

This may be an option, but how can I do so? As per Accessibility Inspector, it is apparently not a menu item at all, it is a “button.” How would GUI scripting even know that the menu exists when I cannot give a stable screen location and it is not part of an app’s menu? The app is a background app that does not have a menu–it only has a button that it placed in the left end of the series of menus that exist at the right end of the menu bar. Is there a way to search for a menu item based upon a menu index for a “button”?

The question simply becomes: Is there a way to click a menu item of a “button” that is placed by an app in the menu bar? My attempts at the following have all failed:

tell application “System Events” to tell process “xBack”
return button 1
return button “” of menu 1
return button 1 of menu 1
return button “” of menu bar 1
return the value of attribute “AXTitle” of menu item “Stop” of menu 1 of menu bar 1
return the value of attribute “AXTitle” of menu item “Stop” of menu 1 of button “” of menu bar 1
end tell

If it simply can’t be done, I’d love to know!

Thank you!

I just downloaded the app and tested a few things, because GUI scripting is 90% trial and error

This code should select the menu items Stop (or Start)


tell application "System Events"
	tell process "xBack"
		tell menu "Background" of menu bar item "Background" of menu bar 1
			pick menu item "Stop" -- or "Run" for Start
		end tell
	end tell
end tell


but it doesn’t take effect immediately until you click the menu bar icon.
I’d recommend to contact the developers.

Thank you, Stefan!

I had no idea such a menu existed; I now know to use Interface Builder to check for vital, missing information!

Unfortunately, the developer has never responded to any of my emails. (I do TRY not to pester this list! :wink: ) I suppose I can use System Events to check to see which apps are running and then attempt to calculate a screen location for the button.

Thank you for such prompt and useful information!

FYI, the combination of xBack (running a slimmed-down version of “Flurry”), TerraVista, MoonDock, Snö, and MenuShade makes an amazing desktop, including live updates of the Earth’s cloud cover and Moon phases!

Blessings and thank you!

There is an easier way,
I opened the .nib-file with Interface builder and discovered shortcuts for the menu items

activate application "xBack"
tell application "System Events"
	tell process "xBack"
		keystroke "r" using command down
	end tell
end tell

starts the screen saver and

activate application "xBack"
tell application "System Events"
	tell process "xBack"
		keystroke "." using command down
	end tell
end tell

stops

Bless you!

I opened the .nib-file with Interface builder and discovered shortcuts for the menu items

I though that was how you found the menu items in the first place, how did you know the menu “Background” was there if not via Interface Builder?? A newbie needs to know! :wink:

On a minor note, the “Open this Scriplet in your Editor:” link used to work, but now strips out all the line breaks in both Smile and Script Editor. Is that because I am still running 10.4.11? Thank you!

In Script Debugger I went thru the UI elements of xBack with its Explorer

I don’t think so. But I don’t use neither Smile nor Script Editor.

A wealth of information, Stefan!

Thank you so much for your efforts!

Blessings.