1

I'm trying to use the suggestions for adding menu items discussed here: https://mathematica.stackexchange.com/a/909/44139

When I add ...

LinkWrite[$ParentLink, 
 AddMenuCommands[
  "BackgroundDialog", {Delimiter, 
   Item["M&y Color", Background -> RGBColor[0.980, 0.941, 0.902]]}]]

To $UserBaseDirectory\FrontEnd\init.m I get a startup error

Could not process unknown packet "LinkWrite".

In a notebook, the command executes and adds the menu item. It's been a long time since I tried to hack the init.m. I've forgotten how. Any suggestions?


Edit: With the help of the comments, I concluded that the suggestion I was attempting to implement is not a good solution to my problem. Instead I copied
$InstallationDirectory\SystemFiles\FrontEnd\TextResources\Windows\MenuSetup.tr

to

$UserBaseDirectory\SystemFiles\FrontEnd\TextResources\Windows\MenuSetup.tr

,adding the necessary directories. I then modified the copy, which Mathematica prioritizes over the original.

I'm not sure what to do about this question, since it might be useful to someone else; even if the answer is "Don't do that!"

  • It's a tricky business talking to the front end during kernel initialization, you might have better luck wrapping the call in RunScheduledTask – Jason B. Jun 16 '22 at 22:51
  • 2
    Couple of things. 1.) The FrontEnd's init.m is for preferences, not arbitrary expressions. It is frequently overwritten. The Kernel's init.m is a safer place to put items like this. 2.) I would not recommend writing arbitrary expressions to links you did not open/manage. I would probably recommend using FrontEndExecute[] after checking $Notebooks is True. – ihojnicki Jun 16 '22 at 23:47

0 Answers0