5

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.

b3m2a1
  • 46,870
  • 3
  • 92
  • 239
dennis
  • 51
  • 2

1 Answers1

3

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.

b3m2a1
  • 46,870
  • 3
  • 92
  • 239
  • Thank you very much. – dennis Oct 30 '17 at 07:45
  • 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 – dennis Oct 30 '17 at 08:21
  • @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+-? – b3m2a1 Oct 30 '17 at 08:52
  • Ok, thanks, I see 1 of my mistakes : used the negative in the calc keyboard. I'll keep you informed. – dennis Oct 30 '17 at 09:05
  • 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... – dennis Oct 30 '17 at 09:19