List of menu items

Hello,

I would like to write a script that helps someone to write a menu item’s correct position, e.g. for a blog post. The idea is relatively simple. I would either display a search box where one could enter the menu item’s name, and then use the script to search for it, or display a menu with menus, then a list of menu items, then a list of sub-menu items, then the user can click OK and the correct path to the menu item is inserted.

An example:

Let’s assume I would like to tell someone how to find the Superscript option in TextEdit. The script would allow to search for “superscript” and then insert something like: “Format → Font → Baseline → Superscript”.

In another example, where one doesn’t know the correct menu items’ name:

They would execute the script, which would then display:

  • File
  • Edit
  • Format
  • View
  • Window
  • Help

Then the user could click Format, which would then display the contents of the Format menu, then the contents of the Font menu, etc.

I hope this all makes sense. I know how to get the name of every menu item, but I can’t figure out how to keep the hierarchy intact.

Thank you for the help!

Hi Zett,

A lot of that is in the Help menu. The Help menu might give you ideas. Although, I don’t see many movies. You could make a movie that shows the cursor moving to the right menus. Or create pictures with Preview using bubbles. A picture is worth a thousand words. :slight_smile: Your last idea could use a ‘choose from list’ dialog searching for the items using ui element scripting. In the past, Apple had an easy way to create your own help movies. Don’t know if it is still there.

It sounds interesting though, although it sounds like a lot of work. It might help to know what you know. Right now I’m trying to finish up on something.

Good Luck,
kel

No movie. This is not supposed to be a replacement for documentation or anything. Just a script to let one choose a menu item and insert its path. As in my example. Choose Superscript for TextEdit and insert the text “Format → Font → Baseline → Superscript”.

Hello.

You may have a look at The scripts in this thread

There is also a script by Apple (Probe Menu Bar) that you should look for that may help you achieve your goal.

(*
 Probe Menu Bar
 
 This script uses UI element scripting to return a list of every menuitem
 of every menu for every application currently running.
 
 Copyright © 2013 Apple Inc.
 
 You may incorporate this Apple sample code into your program(s) without
 restriction.  This Apple sample code has been provided "AS IS" and the
 responsibility for its operation is yours.  You are not permitted to
 redistribute this Apple sample code as "Apple sample code" after having
 made changes.  If you're going to redistribute the code, we require
 that you make it clear that the code was descended from Apple sample
 code, but that you've made changes.
 *)
 
 try
     tell application "System Events"
         get properties
         get every process
         tell process "Finder"
             get every menu bar
            tell menu bar 1
                get every menu bar item
                get every menu of every menu bar item
                get every menu item of every menu of every menu bar item
                get every menu of every menu item of every menu of every menu bar item
                get every menu item of every menu of every menu item of every menu of every menu bar item
            end tell
         end tell
         display dialog "The 'Probe Menu Bar' script was executed, it uses UI element scripting to return a list of every menuitem
 of every menu for every application currently running, to see results run it within AppleScript Editor."
     end tell
on error errMsg
	display dialog "Error: " & errMsg
end try

Best of luck. :slight_smile:

Actually, I think this doesn’t make sense. If the user doesn’t know the name, then how can the computer know what the user is looking for. The computer can only do what you tell it to. It can’t read your mind. I don’t understand.

Edited: the only thing you can program into the computer is make a whole list of all the user’s options. Then the user can choose from that list.

Edited: one option might be that if the user enters something, then the computer can find something that sounds like it. In unix, it might be something like ‘apropos’. In an internet search field, they list things that might sound like something the user has entered. Note that with AppleScript, this might take a very long time.

gl,
kel