9

I want to add some items to the Mathematica 8.0.4 Help menu (under Mac OS X). In

 [$UserBaseDirectory]/Autoload/FrontEnd/init.m

I have the following cell:

  FrontEnd`AddMenuCommands["OpenHelpLink",{Delimiter,
  Item["Installed Add-Ons",FrontEndExecute[FrontEnd`FrontEndToken["OpenHelpLink",    
       {"guide/InstalledAddOns",Automatic}]]],
  Item["Standard Extra Packages",FrontEndExecute[FrontEnd`FrontEndToken["OpenHelpLink", 
        {"guide/StandardExtraPackages",Automatic}]]],
  Delimiter}]

but the items are not added to the Help menu when I start Mathematica.

Do I have the syntax wrong, or should this go in some other init.m?

István Zachar
  • 47,032
  • 20
  • 143
  • 291
murray
  • 11,888
  • 2
  • 26
  • 50
  • Possible duplicate of http://mathematica.stackexchange.com/q/907/46? – Heike Feb 10 '12 at 20:05
  • so, does this work when you run it interactively? – acl Feb 10 '12 at 20:24
  • You are missing a closing ] in the code above. It works for me when put under $UserBaseDirectory/Autoload/PacletManager/Configuration/FrontEnd. It seem that the path you are using is not scanned for init.m files when MMa is starting up. – Matariki Feb 10 '12 at 20:29
  • Sorry about the missing terminal ] in the code; a copy-paste error. I fixed that. – murray Feb 10 '12 at 22:41
  • About@Matariki comment that the init.m can be placed in $UserBaseDirectory/Autoload/PacletManager/Configuration/FrontEnd: I'm using versioned preferences, and that directory already has an init_8.0.4.m with the following code:

    SetOptions[$FrontEndSession, PrivatePaths -> {"SystemResources" -> {ParentList}, "TextResources" -> {FrontEnd\FileName[{"/Applications/Math/Mathematica.app/
    AddOns/Applications/WolframAlphaClient/./FrontEnd", "TextResources"}, "PacletManager" -> True, "Prepend" -> True], ParentList}}]`

    What to do?

    – murray Feb 10 '12 at 22:45
  • People, people: please use backticks for code, and use the techniques here if need be. I've had to fix a few comments that were interacting badly with MathJax because they weren't within backticks... – J. M.'s missing motivation Feb 11 '12 at 09:19
  • OK, confirmed that the added init.m can go into $UserBaseDirectory/Autoload/PacletManager/Configuration/FrontEnd without interfering with versioned-preferences file init_8.0.4.m already there. (That is, the new init.m is not oeverwritten when I start Mathematica with clean preferences & cache -- and the commands there do work to add menu items.)

    Thanks to all! This was not easy to track down, except with your help, due to the dire lack of documentation.

    – murray Feb 11 '12 at 15:48

1 Answers1

8

I can only speak for Windows but I would expect the solution should be similar for Mac.

I created a file $BaseDirectory\FrontEnd\init.m

In that file I added the following lines. Note they are slightly different than what you provide but should do what you want.

FrontEndExecute[AddMenuCommands["AboutBoxDialog",{Delimiter,
  Item["Installed Add Ons",FrontEndExecute[FrontEnd`FrontEndToken["OpenHelpLink",
    {"guide/InstalledAddOns",Automatic}]]],Item["Standard Extra Packages",
       FrontEndExecute[FrontEnd`FrontEndToken["OpenHelpLink",
          {"guide/StandardExtraPackages",Automatic}]]]}]]

I attempted to do this using $UserBaseDirectory\FrontEnd but Mathematica insists on wiping out any changes I make to the init.m file that already exists there.

EDIT:

Following the comment by @Matariki one can place the init.m file in $UserBaseDirectory\Autoload\PacletManager\Configuration\FrontEnd\ instead. I'm not sure which is preferable. The $BaseDirectory installation should add the customization for any user on the machine whereas the $UserBaseDirectory option will only work for the selected user.

Extension:

Also worth noting is that "AboutBoxDialog" is a front end token that can be found in MenuSetup.tr located in $InstallationDirectory/SystemFiles/FrontEnd/TextResources/.

These tokens, to my knowledge, are the only way to control the placement of new commands in menus. I could for example have added a background color to the Format>Background Colors menu by noting that "BackgroundDialog" is the token closest to the relevant menu in MenuSetup.tr. Adding the following code to the previously mentioned init.m will add a Linen color to the Background Colors sub-menu.

FrontEndExecute[ 
  AddMenuCommands["BackgroundDialog", {Delimiter, 
   Item["L&inen",Background->RGBColor[0.980,0.941,0.902]]}]];
Andy Ross
  • 19,320
  • 2
  • 61
  • 93
  • Drat: I was hoping I could isolate any such change to $UserBaseDirectory and away from $BaseDirectory -- so that the change would definitely be preserved across upgrades or (in case needed) re-installation. I think the only difference between your version and mine is that I included Delimiter before and after the other items. My version of the init.m does work for Mac in $$BaseDirectory/FrontEnd/init.m. – murray Feb 10 '12 at 21:58