Scripting a Menu Bar Macro With UI Browser

I am attempting to write a simple script to click on Apple > Restart... UI Browser app is not helping me much at the moment.

When I click with the UI Browser on the "Restart..." button, it returns it as UI Browser process element and not as MacOS element. So I don't know which process is running that button of the MenuBar and I am therefore unable to trigger it with a script.

I've tried to use the Accessibility Inspector but I can't wrap my head around it.

You need to set the target to something other than UI Browser.app - specifically the app that is responsible for processing the Restartbutton. As I’m not at my desk I can’t tell you what that might be; something like “system events” maybe?

System Events has a command that can be run directly.

So the AppleScript could be as simple as this...

tell application "System Events" to restart

1 Like

@djgregg has given you the solution but so you know, here is a screenshot taken of UI Browser that shows the Reset button:

You can use the Target dropdown menu in UI Browser, and find CoreServicesUIAgent.app using the following path: "MacintoshHD:System:Library:CoreServices:CoreServicesUIAgent.app

Hey Alex,

Is there any specific reason you're trying to use UI Browser to do this?

There are two direct methods available using Keyboard Maestro native actions:

The Select or Show a Menu Item action and the Restart Computer action.

Restart Mac v1.00.kmmacros (5.0 KB)
Keyboard Maestro Export

-Chris

3 Likes

Sorry for the late reply and thanks for this useful little macro. Duly noted!

1 Like