5

Which commands can you put in KeyEventTranslations.tr ? There is an extensive list of FrontEndTokens, but what else can you use? Why something like this doesn't work:

Item[KeyEvent["r", Modifiers -> {Command}],
 FrontEndExecute[{
    FrontEnd`KernelExecute[ToExpression["Quit[]"]],
    FrontEndToken[SelectedNotebook[], "EvaluatorStart", "Local"]
 }]
],

With FrontEnd``KernelExecute` one could put any command there, but what's the trick?

Edit (some more observations)

This does work in MenuSetup.tr, like explained here (and of course in the current session). Menu items can be executed by a Kernel or FrontEnd. However, for each item there can be only one MenuEvaluator, so after quitting Kernel the rest of commands will not be executed.

Also, for some reason, KernelExecute, when started from Menu or a button (not from a Cell), is not only queued to Kernel, but has priority!

Vladimir
  • 1,503
  • 1
  • 12
  • 28
  • You can also use the EvaluatorQuit token. http://mathematica.stackexchange.com/questions/6224/best-way-to-add-keyevents-and-faster-quit – Szabolcs Mar 13 '13 at 02:50
  • @Szabolcs No, actually I reached here because I wanted to make Restart Kernel shortcut. And EvaluatorQuit token pops up a dialog window. However, quitting kernel may just be enough as it will start automatically on next command. Nevertheless, my question stays- why can't you put explicit commands (for kernel execution) in KeyEventTranslations.tr? What else can one put there besides FrontEnd tokens? – Vladimir Mar 13 '13 at 11:58
  • 3
    But KernelExecute works. Look here – Rolf Mertig Mar 14 '13 at 11:09
  • @RolfMertig That is really a relief! Perhaps for KernelExecute is necessary to include MenuEvaluator? But it doesn't make sense, it's not MenuItem, either. And so when you create file in $UserBaseDirectory Mathematica will load it preferably to the original one in $InstallationDirectory ? – Vladimir Mar 14 '13 at 11:44
  • Or perhaps because I called it as FrontEndExecute[KernelExecute[...]] :D – Vladimir Mar 14 '13 at 12:52
  • You don't have to put them in KeyEventTranslations.tr, you can use MenuSetup.tr: MenuItem["Quit Current Kernel",KernelExecute[SystemModule[{nb},nb =SystemNotebookPut[SystemNotebook[{SystemCell["Quitting Kernel!", "Title",TextAlignment -> Center]},SystemWindowMargins -> {{300, 300}, {300, 300}}]];SystemPause[1];SystemNotebookClose[nb]];SystemQuit[];],MenuEvaluator -> Automatic,MenuKey["Escape", Modifiers ->{"Control"}]] All I'm missing is something like SystemStartKernel[]` for this to be practical. – Charlotte Hadley Jun 18 '13 at 05:58
  • I don't really understand what you are trying to say, nor what kind of problem you encountered. Have you gained better understanding of these commands in last days? If there is something still unclear, consider posting a new question. – Vladimir Jun 25 '13 at 23:12
  • The `FrontEnd`` context is a dummy, that is used in the kernel only to make these symbols inert; they are then passed to the FE where the context is stripped and they are interpreted. Since KeyEventTranslations.tr is processed by the FE directly, I think you don't need to add the dummy context. – Oleksandr R. Apr 24 '14 at 16:59
  • @Vladimir I don't know exactly what was wrong, I think I had two definitions for the same key, of which one was wrong. Anyway, it works now and I have deleted my answer. – Jacob Akkerboom Apr 25 '14 at 08:31

0 Answers0