Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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!

share|improve this question
    
You can also use the EvaluatorQuit token. mathematica.stackexchange.com/questions/6224/… –  Szabolcs Mar 13 '13 at 2: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
2  
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
show 3 more comments

1 Answer

Maybe I am wrong, but I think that KernelExecute will not work in the usual file KeyEventTranslations.tr, whereas it does work KeyEventTranslations.tr file created by Rolf's package (in a subdirectory of $UserBaseDirectory).

Response to comment

It seems the item

Item[
KeyEvent["p", Modifiers -> {Option, Shift}], 
      KernelExecute[ToExpression["Private`evaluation"]]
      ,
 MenuEvaluator -> Automatic
]

does work in the file created by Rolf's package, but not in the original KeyEventTranslations.tr. I jumped to the conclusion that KernelExecute did not work in general here, because I could not get it to work. The item

Item[
KeyEvent["k", Modifiers -> {Option, Command}], 
      KernelExecute[ToExpression["Quit[]"]]
      ,
 MenuEvaluator -> Automatic
]

does work for me in both files.

The reason for me to make the first item, is to be able to attach definitions to Private`evalation that can be accessed with this hotkey. The error I get is

Could not process unknown packet "Private`evaluation".

share|improve this answer
    
You are wrong, I've tried both of them and Rolf gave good example. The problem in my code, I explained in the edit. –  Vladimir 8 hours ago
    
@Vladimir thank you for the reply. I must say I do not understand your edit section, I don't know anything about menuitems, although they seem similar to shortkeys. I highly doubt it matters, but what OS and version are you on? –  Jacob Akkerboom 8 hours ago
    
@Vladmir If I cut and paste item into the $UserBaseDirectory subfolder, it works. If I cut and paste it back it doesn't work. I suppose this is what you have tried as well? –  Jacob Akkerboom 7 hours ago
    
I am using OS Mavericks. At the moment I do not have any modified files in userbasedirectory, but I did run Rolf's code when I first saw it. Afterwards, I decided to modify system files directly, though second option is more secure. What exactly are you interested at, or what do you want to do? I can explain you the question as well as the edit (basically - the answer). –  Vladimir 4 hours ago
    
@Vladimir Ah, I am also using Mavericks, so that's not it. I have update my answer to respond to you. –  Jacob Akkerboom 4 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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