Can We Use KM Variable with Action "Select or Show a Menu Item"?

I would like to use KM variables to set the font face and font size in the Action "Select or Show a Menu Item", but it doesn't seem to work. The macro just stops at this Action.
Can I make this work? If so, how?

Here are my Actions:

Prior to the "Select...Menu" Action, I set the Variables:

Set Variable ‘StdFontFace’ to Text Verdana

Here's the "Select...Menu" Action:

TIA for your help.

Hey Michael,

Here's the skinny:

I remembered this post but couldn't find it on the board due to the mediocre search, but Google was my friend:

menu AND variable site:

Second link down.

You can do this by resorting to System Events & UI-Scripting:

set topLevelMenu to "Window"
set subMenuItemOne to "Macro Library"

tell application "System Events"
  tell application process "Keyboard Maestro"
    tell menu item subMenuItemOne of menu 1 of menu bar item topLevelMenu of menu bar 1
      if enabled then
      end if
    end tell
  end tell
end tell

But UI-Scripting is not for the faint of heart. I bought UI Browser long ago to save my hair.


Here, FWIW is a generic function (Javascript for Applications, so Yosemite-only) for clicking sub-menu items:

( Change the application name and the chain of menu titles, checking for exact spelling )

// Click an OS X app sub-menu item
// 2nd argument is an array of arbitrary length (exact menu item labels, giving full path)

menuItemClick("Microsoft Word", ['View', 'Sidebar', 'Thumbnail Pane'])

function menuItemClick(strAppName, lstMenuPath) {
	var oApp = Application(strAppName),
		lngChain = lstMenuPath.length,
		blnResult = false;

	if (lngChain > 1) {

		var appSE = Application("System Events"),
			lstApps = appSE.processes.where({
				name: strAppName
			procApp = lstApps.length ? lstApps[0] : null;

		if (procApp) {
			var strMenu = lstMenuPath[0],
				fnMenu = procApp.menuBars[0].menus.byName(strMenu),
				lngLast = lngChain - 1;

			for (var i = 1; i < lngLast; i++) {
				strMenu = lstMenuPath[i];
				fnMenu = fnMenu.menuItems[strMenu].menus[strMenu];

			blnResult = true;
	return blnResult;

Thanks Chris. As always you’re quick to reply.
But, as you say, “UI-Scripting is not for the faint of heart”. That’s much more complicated than I want to pursue. I was just trying to add some actions to make it easier for others to customize.

I did the search you quoted, and actually it came up with a very interesting hit at the top:
Feature Request - Allow using variables in “Select or Show a Menu Item” action

Another KM user make the same request (as I did) about a month ago!

So, @Peter, with 2 requests, how can you deny us? :grinning:

Did you read my reply in that topic?

Sorry, I seem to be slipping today. I missed it.

But thank you very, very, much!

Just for others reading this thread, here’s what Peter said: