Function Repository Resource:

AddMenuItem

Source Notebook

Add a menu item in a Wolfram desktop system

Contributed by: Wolfram Staff

ResourceFunction["AddMenuItem"]["after",item]

adds a new menu item to the Wolfram sytem front end after the specified menu item.

ResourceFunction["AddMenuItem"][token,{item1,item2,}]

adds several menu items.

Details and Options

The specified menu item "after" can be a menu token or a front end command corresponding to an existing menu item.
You may be able to find suitable menu tokens and commands in one of the files in FileNames["MenuSetup.tr",FileNameJoin[{$TopDirectory,"SystemFiles","FrontEnd","TextResources"}],Infinity].
item is typically a menu item object in the form MenuItem["menustring",cmd,options], where cmd is a front end token or command and options can include "MenuKey", "Modifiers", Method, MenuEvaluator and others; see "MenuSetup.tr" for examples.
Items added with ResourceFunction["AddMenuItem"] persist during the same front end session.
ResourceFunction["AddMenuItem"] works only in the Wolfram desktop systems.
Items added with ResourceFunction["AddMenuItem"] can be removed with the resource function RemoveMenuItem.

Examples

Basic Examples (2) 

Create an alternative menu item for maximizing the input notebook window after the Close Other Windows menu item:

In[1]:=
ResourceFunction["AddMenuItem"]["CloseOthers", MenuItem["Maximize", KernelExecute[
   SetOptions[InputNotebook[], WindowMargins -> {{0, 0}, {0, 0}}, WindowSize -> Automatic]], "MenuKey"["m", "Modifiers" -> {"Shift", "Control"}], MenuEvaluator -> "System"]]

The current window size:

In[2]:=
Options[InputNotebook[], WindowSize]
Out[2]=

Choose the new menu item or press the keyboard shortcut to maximize the current notebook window and check the new window size:

In[3]:=
Options[InputNotebook[], WindowSize]
Out[3]=

Add a delimiter and a menu item for opening the Function Repository webpage:

In[4]:=
ResourceFunction[
 "AddMenuItem"]["SelectionHelpDialog", {Delimiter, MenuItem["Function Repository", FrontEndExecute[{FrontEnd`NotebookLocate[{URL[
        "https://resources.wolframcloud.com/FunctionRepository"], None}]}]]}]

Scope (1) 

See possible menu item tokens to place new items after:

In[5]:=
Cases[Import@
  First@TakeSmallestBy[
    FileNames["MenuSetup.tr", FileNameJoin[{$TopDirectory, "SystemFiles", "FrontEnd", "TextResources"}], Infinity], Length[FileNameSplit[#]] &, 1], MenuItem[_, s_String, ___] :> s, {1, Infinity}]
Out[5]=

Properties and Relations (1) 

Menu items created with AddMenuItem can be removed with the resource function RemoveMenuItem:

In[6]:=
ResourceFunction["AddMenuItem"]["AllWindowsFront", MenuItem["Open Dialog", FrontEnd`KernelExecute[
   CreateDialog[{TextCell["Close me"], DefaultButton[]}]], MenuEvaluator -> Automatic]]
In[7]:=
ResourceFunction["RemoveMenuItem"]["Open Dialog"]

Version History

  • 1.0.0 – 12 November 2020

Related Resources

License Information