UI Browser - How to copy the report as a usable code line? [SOLVED]

When I see the report of UI Browser for a certain element, excluding the top part where it mentions the application, I get something like this:

	menu bar (menu bar 1)
		menu bar item "Format" (menu bar item 5)
			menu (menu 1)
				menu item "Heading" (menu item 2)

I am working on a macro to convert this to a line that I can use right away.
And before I spend more time on it to then discover that this can be done a different way, is there an option to do it in the app itself? To convert the above to this:

menu item "Heading" (menu item 2) of menu (menu 1) of menu bar item "Format" (menu bar item 5) of menu bar (menu bar 1)

The macro I'm creating will actually provide 2 options, depending on what I want to use, for example maybe I want to use the name of the item itself menu bar item "Format", not the number menu bar item 5, so I'm guessing that even if UI Browser can convert the line, it will only give me the option with the item numbers?

I just finished the macro anyway if someone finds it useful. I know it will be for me.
I included both versions, even though one of them will probably not make any sense most of the time (the one with just the names), but it's still there anyway...

So the workflow that I will be using, in case others want to use it as well:

  • Hover over the item to inspect
  • Click CMD to "freeze" and while holding it, click "View Report"
  • Select and copy the "structure" without the top line (usually the "application", but maybe there are other scenarios where it might change... I don't use it that much to know it yet)
  • Run the macro, as it will convert everything from the Clipboard

So this:

	menu bar (menu bar 1)
		menu bar item "Format" (menu bar item 5)
			menu (menu 1)
				menu item "Heading" (menu item 2)

will become this:

-- original: menu item "Heading" (menu item 2) of menu (menu 1) of menu bar item "Format" (menu bar item 5) of menu bar (menu bar 1)
click menu item 2 of menu 1 of menu bar item 5 of menu bar 1

click menu item "Heading" of menu of menu bar item "Format" of menu bar

Convert UI Browser report to code line.kmmacros (46 KB)

Keyboard Maestro Export

I'm pretty sure someone will come and say that this can be done with 1 shell script or something :joy: but oh well, along the way I've learned a few more things, so it's never wasted time :wink:

If you select "Reference to Selected Element" in UI Browser's AppleScript menu you'll get the format you want, Click Selected Element will give you the click code, and so. These are also available from the popup:

There's probably a bunch of other things that make life easier, but I'm not a user...

1 Like

I knew there was a way... :wink:

Thank you for sharing. And that AppleScript menu has some other interesting options indeed.

When I'm using the Screen Reader and I hold CMD, it seems that the only way to then see the updated information to that element is by clicking View Report, but when I click that, it also opens an extra window that I then have to close (it's an unnecessary step).

Do you know if it's possible to just update the information in the Browser view without opening the extra window with the report? I tried clicking "Switch to Browser" button, but the information doesn't seem to update. It keeps the old element.

As I said -- not a user. Never had the justification before, and now you can't buy a licence. I only got the above screenie by finding yet another machine I haven't run the trial on before, and "⌘ to lock" doesn't work on a remote desktop session.

Best bet may be to page (in no particular order, and apologies for both the assumption and for missing others out) @noisneil, @griffman, or @ComplexPoint...

1 Like

I use it, but sparingly, and just close the extra window when done. I don't use it often enough that it annoys me. I'm just happy the old code still runs :).

-rob.

Old?

I still use UIElementInspector (still downloadable) for this sort of thing -- last updated in 2010!

1 Like

Oh I thought you were saying that because of what you said prior to that: "There's probably a bunch of other things that make life easier". I even thought it was some kind of joke. My bad...

I found a website somewhere, recently, where the developer was actually sharing a workaround to remove the trial limitation or something. I tried it and for some reason it didn't work. Then someone else either on that same website or somewhere else, shared another tip and that's how I use it now. I would like to buy it, but the website is gone and I doubt that the developer would like to still deal with anything related to the app...

Same here.

I guess I will have to do the same thing and not get too picky about it :wink:

True! It's a great piece of software. I saw that someone was trying to develop version 4 or something, but doesn't seem to be happening at all.

There's also this:

1 Like

Will definitely try it. Thanks for sharing. It seems to be way easier and faster than using UI Browser. I will keep UI Browser anyway, just in case, but once I test your macro and it works, it seems like a better option. :muscle:

1 Like