4
$\begingroup$

I am a beginner.

I would like to add a keyboard shortcut to the Format > Text Color > Red menu item.

I know I can type alt-r-x-up arrow-up arrow-return (Windows7). But I want to include this command with others for the (excellent) external shortcut maker that I use (Clavier+). If I don't, Clavier+ is too slow and it ends up in a mess.

I tried to search in the already answered questions, but could not go very far. My ultimate goald would be to have a shortcut for

textcolor=red

"-" (type "negative")

clear formatting

So there are 2 questions :

  1. how and where can I add something like MenuKey["r", Modifiers->{"Control+Alt"}] to type directly in red

  2. is it possible to make macros in Mathematica to concatenate several commands ?

I hope I was clear.

$\endgroup$
  • $\begingroup$ Do those answer work for you: 47474? $\endgroup$ – Kuba Oct 30 '17 at 9:14
2
$\begingroup$

The easiest way to do this is to first copy your MenuSetup.tr file:

Quiet@
    CopyFile[#,
     newSetup =
      If[FileExistsQ@
        StringTrim[#, $InstallationDirectory | $UserBaseDirectory | \
$BaseDirectory],
       StringTrim[#, $InstallationDirectory | $UserBaseDirectory | \
$BaseDirectory],
       FileNameJoin@{$UserBaseDirectory,
         StringTrim[#, $InstallationDirectory | $UserBaseDirectory | \
$BaseDirectory]
         }]
     ] &@FrontEndExecute@
   FrontEnd`FindFileOnPath["MenuSetup.tr", 
    "PrivatePathsTextResources"];
SystemOpen@newSetup

Search in that newSetup for "Text Color"

Replace the MenuItem for "Red" with this:

MenuItem["Red", FontColor -> RGBColor[1, 0, 0], 
 MenuKey["-", Modifiers -> {"Command", "Shift"}]]

Then reset the menu with this:

FrontEndExecute@{
  FrontEnd`FlushTextResourceCaches[],
  FrontEnd`ResetMenusPacket[{Automatic, Automatic}]
  }

Alternately, I have a chunk of code that I detailed here with a better implementation here that lets you do things like this:

FEMenuSetupAdd[
 {"Mathematica", "Format", "Text Color"},
 "Tangerine" :> FontColor -> RGBColor[1, .5, 0],
 MenuKey["-", Modifiers -> {"Command", "Shift"}]
 ]

But I can't fully remember how to remove the MenuKey afterwards, so only use that if you are really feeling it.

$\endgroup$
  • $\begingroup$ Thank you very much. $\endgroup$ – dennis Oct 30 '17 at 7:45
  • $\begingroup$ Thank you very much. Helps to understand how it may work. As I said, I am a beginner. So please excuse... The first block I copied in Mathem. Got the output "failed" after I hit return. So did a copy of MenuSetup and opened it with Notepad++. Could not find Text Color, but "Te&xt Color". Changed the "red" line with your line. Did manually the subtitution with the original file. Re-started Mathematica. Did not work. So I tried several combinations of modifiers, alt (never worked), control (appears in the menu, but does not work, same with shift. Seems can't overwrite a native mathem. shortcuts $\endgroup$ – dennis Oct 30 '17 at 8:21
  • $\begingroup$ @dennis You 100% can overwrite the shortcuts. "Te&xt Color" is undoubtedly just what Windows calls it. What happens, then, when you select a chunk of text and press Control+Shift+-? $\endgroup$ – b3m2a1 Oct 30 '17 at 8:52
  • $\begingroup$ Ok, thanks, I see 1 of my mistakes : used the negative in the calc keyboard. I'll keep you informed. $\endgroup$ – dennis Oct 30 '17 at 9:05
  • $\begingroup$ It works. Thanks a lot. I read the other example you wrote. Very interesting. I suppose it answers to my other question : it IS possible to concatenate several actions. Just needs to program it... $\endgroup$ – dennis Oct 30 '17 at 9:19

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.