Is there a way to use KM to access menu items in, for instance, the "Keyboard" menu, which doesn't have a standard name in the menu bar? I'm looking specifically for a way to select "Show Emoji & Symbols" in an application that has a built-in conflict with the standard hotkey for that function.
Have you tried to select the item in the Edit menu named "Emoji & Symbols"? Then that becomes the frontmost window. (I haven't tried this, but I think it should work in theory.)
This is how you would go about opening Emoji & Symbols using AppleScript to drive the menu item.
Try running it from Apple's anemic Script Editor app, and see if this will work as is on your system.
set bailOutTime to 20
tell application "System Events"
tell application process "SystemUIServer"
tell menu bar 1
tell (first menu bar item whose accessibility description is "text input")
perform action "AXPress"
tell menu 1
tell menu item "Show Emoji & Symbols"
repeat until exists of it
set bailOutTime to bailOutTime - 1
delay 0.25
if bailOutTime ≤ 0 then error "Timeout Exceeded!"
end repeat
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
It works for me on macOS Mojave, but it may require adjustments for other versions of macOS.
I have just tweaked your script so that it will show or hide the Emoji & Symbols panel, depending on whether or not it's already open.
Edit: @ccstone has asked me to mention the version of MacOS this modified script has been tested under. It's the same as for Chris's original script, that is, Mojave.
set bailOutTime to 20
tell application "System Events"
tell application process "SystemUIServer"
tell menu bar 1
tell (first menu bar item whose accessibility description is "text input")
perform action "AXPress"
tell menu 1
if menu item "Show Emoji & Symbols" exists then
set symbols_menu to "Show Emoji & Symbols"
else
set symbols_menu to "Hide Emoji & Symbols"
end if
tell menu item symbols_menu
repeat until exists of it
set bailOutTime to bailOutTime - 1
delay 0.25
if bailOutTime ≤ 0 then error "Timeout Exceeded!"
end repeat
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
This looks really promising, y'all. Thanks so much! Cutting and pasting @kevinb's version into ScriptEditor I get this:
error "System Events got an error: Can’t get menu bar 1 of application process "SystemUIServer". Invalid index." number -1719 from menu bar 1 ofapplication process "SystemUIServer"
I assume that's because my menu items are in a different order than @kevinb's, so I'll try digging in a little over the next few days to see if I can find the right tweaks.
Thanks tons, both @ccstone and @kevinb, for the huge head start!
Ha echoed! I hadn't noticed that "Emoji & Symbols" shows up in the Edit menu in addition to the Keyboard Input menu. That's a much easier menu to call!
Thanks, y'all, for your patient help and thoughtful suggestions! Problem solved!