Get the Name of Marked Menu Item

How would I convert the name of a marked menu item (Navigator in this case) to a variable

Probably via AppleScript I think...?

image

Mike
Yes AppleScript. try something like this - you'll need to adapt it with the name of your app and the menu you're looking under.

tell application "System Events"
	tell menu bar of process "YOUR APP"
		tell menu "Window" -- Change to which menu
			set checkedItem to first menu item whose attribute "AXMenuItemMarkChar"'s value is "✓"
 -- i don't get why this returns a "list of 1" instead of a menu item,
--  but we have to look inside the list at its 1st item
			return title of item 1 of checkedItem
		end tell
	end tell
end tell
3 Likes

Thanks - this works great
I have figured it out with a series of if/thens (both as KM actions and within AppleScript)
Those worked well too - and I was able to make a few conditional exceptions in case there was no checkmark

I'll store this script for later use!

1 Like

Hey Mike,

Please always tell us what app you're working in. If someone else has access to the same app it generally streamlines the Q&A process.

-Chris

1 Like

I looked for the same thing but it was in a submenu so I had to do this. Had some trouble understanding that each submenu has both a menu and a menu item element.

tell application "System Events"
	tell menu bar of process "YOUR APP"
		tell menu 1 of menu item "Submenu" of menu "Window" -- Change to which submenu
			set checkedItem to first menu item whose attribute "AXMenuItemMarkChar"'s value is "✓"
			-- i don't get why this returns a "list of 1" instead of a menu item,
			--  but we have to look inside the list at its 1st item
			return title of item 1 of checkedItem
		end tell
	end tell
end tell