I'm looking for a general "recipe" to do with a keyboard shortcut what I currently do with a PasteButton
. Here is a working toy example PasteButton
:
PasteButton[Subscript[Ω, \[SelectionPlaceholder]]]
It generates a capital Greek letter Omega (type in as \[CapitalOmega]
) with a selection placeholder (black square) in the subscript.
To "keyboard-shortify" it, I know that I have to modify the file KeyEventTranslations.tr in
OS-dependent/Mathematica/11.0/SystemFiles/FrontEnd/TextResources/
but what I have to put into this file is a lot more complicated than just copying from how the PasteButton does it.
If I wanted just the Ω
without the subscript, associated with the keyboard stroke Control-Shift-Command-O, I would have to put the following:
Item[
KeyEvent["O", Modifiers -> {Control, Command, Shift}],
FrontEndExecute[{
FrontEnd`NotebookWrite[
FrontEnd`InputNotebook[],
"Ω",
After
]
}]
]
but what I tried putting into the .tr file with Subscript
did not work - it always put Subscript[something]
literally into the current notebook
I tried to write some code with SelectionMove[] and SelectionEvaluate[] and putting that into the .tr file, but it didn't work properly, and was awfully hard to test (restarting Mathematica all the time)
A more-than-ideal answer would be a function to which you supply, say, Subscript[Ω, \[SelectionPlaceholder]]
as an argument, and which generates the string to be put into the .tr file as result.
Side question: Is there a way to test the code later being put into the .tr file without restarting Mathematica all the time?
$UserBaseDirectory
and edit that copy. $\endgroup$FrontEnd
menus, too. They won’t work, or won’t work well. $\endgroup$