Documentation for Yuri E. Kandrashkin's OptionsExplorer package says to add the following menu commands in MenuSetup.tr:

   Item["Options &Explorer", KernelExecute[ToExpression["OptionsExplorer[]"]],
   MenuKey["o", Modifiers->{Control,Command}], MenuEvaluator->Automatic]

And I want to accomplish the same thing by a corresponding FrontEnd`AddMenuCommands... expression in an Autoload`PacletManager`Configuration`FrontEnd`init.m.

But I don't find any KernelExecute function.

How to do it?

link|improve this question

78% accept rate
1  
Isn't this just what you get when you type something in a cell in the front end, and hit Shift-Enter? So it is just telling the kernel to run the code inside its brackets. – Verbeia Feb 20 at 2:17
If I try to evaluate from a notebook input cell the FrontEnd`AddMenuCommands expression that includes that KernelExecute expression, it colors KernelExecute to indicate it's an unknown name. And trying the same thing from the indicated init.m seems to accomplish nothing -- but then perhaps I misunderstood what I need as the first argument to AddMenuCommands: I used "Input from Above", which is on the Insert menu. – murray Feb 20 at 2:29
See this related MathGroup posting. The function KernelExecute appears to be undocumented but exists and just tells the main kernel to run its argument. Try adding those commands into the file as instructed and see if it works. – Verbeia Feb 20 at 2:30
Rd @Verbeia's comment: the linked MathGroup posting by John Fultz concerns directly editing KeyEventTranslations.tr. But I'm not trying to do that; I want a way that makes changes only in $UserBaseDirectory, not $InstallationDirectory. Hence I'm trying to edit Autoload`PacletManager`Configuration`FrontEnd`init.m. Moreover, I'm trying to insert an Item there that does two things: (1) create a new menu item (on the Insert menu); and (2) sets up a corresponding shortcut key -- as I showed in Kandrashkin's code snipped that appears in my question. – murray Feb 20 at 16:00
Here's what I added to the indicated init.m: FrontEnd`AddMenuCommands[ "Input from Above", {Delimiter, Item["Options &Explorer", KernelExecute[ToExpression["OptionsExplorer[]"]], MenuKey["o", Modifiers -> {Control, Command}], MenuEvaluator -> Automatic]}]; But after restart (with clean cache) nothing gets added to the Insert menu. Did I not properly identify the existing menu keyword in the 1st argument to AddMenuComands? Is something else wrong? – murray Feb 20 at 16:08
feedback

1 Answer

You can add the menu command to your Insert menu using AddMenuCommands in the following manner. (These modifications will only persist for the current front end session.)

First a demo function, just creating a dialog:

FrontEndExecute[FrontEnd`AddMenuCommands["DuplicatePreviousOutput",
  {Delimiter, MenuItem["CreateDialog &Demo",
    FrontEnd`KernelExecute[CreateDialog[{TextCell["Click OK to close"],
       DefaultButton[]}]], 
    MenuKey["D", Modifiers -> {"Control", "Shift"}],
    System`MenuEvaluator -> Automatic]}]]

(Note the required context specification for MenuEvaluator.)

This version will run OptionsExplorer[]

FrontEndExecute[FrontEnd`AddMenuCommands["DuplicatePreviousOutput",
  {Delimiter, MenuItem["Options &Explorer",
    FrontEnd`KernelExecute[ToExpression["OptionsExplorer[]"]],
    MenuKey["O", Modifiers -> {"Control", "Shift"}],
    System`MenuEvaluator -> Automatic]}]]
link|improve this answer
Which init.m among the many in the tree? – murray Feb 22 at 20:10
Where's the corresponding init.m for Mac OS X to what @Chris Degnen gives in C:\Documents and Settings\Chris\Application Data\Mathematica\Kernel for Windows? – murray Feb 23 at 17:08
@murray evaluate this: FileNameJoin[{$UserBaseDirectory, "Kernel"}] – Mr.Wizard Feb 24 at 22:22
feedback

Your Answer

 
or
required, but never shown

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