Click "View as Analog" menu item

How can I script clicking the “View as Analog” menu item?

It’ll be tough to help without a clue about the application that supports that menu item.

I found a .menu file, but I don’t know how to script it. There doesn’t seem to be any background app running that supports the clock though.

Hi Jamie,

the easiest way is

do shell script "defaults write com.apple.MenuBarClock ClockDigital Yes" -- Yes: digital, No: analog
do shell script "killall SystemUIServer"

Thanks, that does what I want it to. Is there any other way to do it, without restarting the menu bar?

Try this:

activate application "SystemUIServer"

tell application "System Events"
	tell process "SystemUIServer"
		set v to value of attribute "AXDescription" of menu bar items of menu bar 1
		repeat with i from (count v) to 1 by -1
			if item i of v is "clock menu extra" then exit repeat
		end repeat
		tell menu bar item i of menu bar 1
			click
			delay 0.1
			click menu item "View as Analog" of menu 1
		end tell
	end tell
end tell

I tried it with

tell 1st menu bar item of menu bar 1 whose value of attribute "AXDescription" is "clock menu extra"

but it returned a wrong menu bar item, I don’t know why

Thanks, that is perfect!