I want to edit my menus and know I can do this via MenuSetup.tr but can I do this in real time? Can I do it temporarily?

Moreover can I change whether the changes are permanent or not / how can I make edits with minimal amounts of syntax and manual editing?

I do this differently to @MB1965.

SetOptions[$FrontEndSession, MenuConfigurationFile -> "path/to/alternative/MenuSetup.tr" ];  and then to restore the menus: SetOptions[$FrontEndSession,
];


I find this easy and can be done readily on the fly, switched on and off with buttons etc.

• Fun. Had no idea that option existed (I pulled my stuff from the PacletManager code). Do you just edit your MenuSetup.tr files by hand or do you have code for that? May 12, 2017 at 23:39
• I do a manual edit in a text editor. May 12, 2017 at 23:49
• Very nice, how did you find that one? Do you know as similar one for "KeyEventTranslations.tr"? May 13, 2017 at 20:10
• @AlbertRetey that is the only one I know unfortunately May 13, 2017 at 23:27

The answer to the first one is very simple. After you make changes to your MenuSetup.tr file simply call

FrontEndExecute@{
FrontEndFlushTextResourceCaches[],
}


The first part gets the MenuSetup.tr loaded and the second applies the actual changes. If you add palettes/stylesheets or a new FE directory, etc, the second call will load those resources too.

The question of temporary-ness is also not bad.

All we have to do there is prepend a new directory to which will contain our MenuSetup.tr

CurrentValue[$FrontEndSession, {PrivatePaths, "TextResources"}]  By setting this to, say $TemporaryDirectory we get what we need for temporary-ness.

### Convenient editing (package only)

Go here for all of this dumped as a package

But we can do yet one better.

Looking at the structure of the menu expressions we can note they're generally tree-like (with some complications) so we should be able to edit them like a nested Association. All we really need to do it unspool them into an Association structure.

Note that this will be made harder by things like MenuItems that share a title (but differ in their MenuKey expression) and AlternateItems and LinkedItems expressions, but overall it's not too bad. And for good measure we'll want a respooling mechanism.

In the attached code package these are the functions feUnspoolMenuExpr and feRespoolMenuExpr respectively.

Then we'll link into the *.tr editing structure I outlined here so we can conveniently specify where to dump our MenuSetup.tr file and simplify the dump procedure itself.

The main useful piece of functionality there is the $FEMenuSetupDirectory constant which is a FrontEndFileName specifying where the data should go. We then unspool the standard Menu structure into the constant (well, constant interface) $FEMenuSetup and we simply use our respooler and some front-end processing to dump an appropriate string-form for our MenuSetup.tr. (feMenuSetupExport)

And then by providing edit functions on $FEMenuSetup (FEMenuSetupAdd, FEMenuSetupDrop) we can very quickly and easily perform interesting edits, such as: FEMenuSetupDrop["Palettes"]  And FEMenuSetupAdd["StackExchange", "MSE" :> FrontEndExecute[{ FrontEndNotebookLocate[{ URL["https://mathematica.stackexchange.com"], None }] }] ];  And clicking on that opens up the main MSE page. None of this required a restart or anything of that nature. It's just a simple edit like this. One still needs to know how the front-end evaluates things (e.g. use the FrontEnd  functions), but it allows for greater flexibility and customization. And if you don't like your changes reverting is as simple as deleting and reloading, which has its own convenience function (FEResetMenuSetup) and syntax: $FEMenuSetup =.


My implementation of this is in the package I linked to earlier to play with.

• I didn't know about FrontEndExecute@{ FrontEndFlushTextResourceCaches[], ResetMenusPacket[{Automatic, Automatic}] } May 12, 2017 at 23:41
• @MikeHoneychurch the ResetMenusPacket call can also take a Menu expression. I had a different question where I played with that. Lots harder though. The FrontEndFlushTextResourceCaches[] is really just a general-purpose reset of the FrontEndResource stuff. It works for most stuff (all I have left to work out is how to get it to work with the KeyEventTranslations.tr file). Do you have a special option for those, too? May 12, 2017 at 23:43
• no. unfortunately just for the menu configuration -- there may be special options but I do not know them May 12, 2017 at 23:45
• @MikeHoneychurch I just checked and there are no options matching Key Event or Translations outside of the standard stuff. Shame. May 12, 2017 at 23:46