I'm trying to create Menu Command that selects all cells in a notebook and closes them. I am able to select all the cells but cannot close them. Below is my attempt I placed in an init.m file.

     "Close All Groups", {FrontEnd`KernelExecute[
       SelectionMove[InputNotebook[], All, Notebook]];
       FrontEndToken[InputNotebook[], "SelectionCloseAllGroups"]]},
     FrontEnd`MenuKey["c", FrontEnd`Modifiers -> {"Control"}],
     System`MenuEvaluator -> Automatic

I believe my problem is using the FrontEndToken in the init.m file. I'm not sure how to use them in this case.


Try this instead...

   MenuItem["Close All Groups",
      SelectionMove[InputNotebook[], All, Notebook];
    FrontEnd`MenuKey["c", FrontEnd`Modifiers -> {"Control", "Shift"}],
    System`MenuEvaluator ->Automatic]

I've moved the keyboard accelerator to Control + Shift, mainly for the benefit of Windows and Linux users.

| improve this answer | |
  • $\begingroup$ This worked. This should help me in the future with frontenstokens in unit.m files. I get lost sometimes with namespaces. $\endgroup$ – Michael McCain Mar 12 '19 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.