30
$\begingroup$

I would like to know if I can modify key bindings without being able to modify the KeyEventTranslations.tr in the installation directory.

So maybe putting another one in my home dir and linking to it in some way?

I have the same question as above. The answer provided there seems not doable. Besides, I use Linux.

$\endgroup$
5
  • 1
    $\begingroup$ Yes, but I don't have direct experience so I won't write an answer. I believe you can just put another KeyEventTranslations in the correct place in $UserBaseDirectory. Check how this script by Rolf Mertig does it. $\endgroup$
    – Szabolcs
    Commented Dec 11, 2014 at 18:53
  • $\begingroup$ This idea of putting a modified copy in the tight location was mentioned already some time ago by @rm-rf I think. $\endgroup$ Commented Dec 11, 2014 at 19:15
  • 2
    $\begingroup$ As @Szabolcs said just copy the file to \SystemFiles\FrontEnd\TextResources\(your os) in $UserBaseDirectory and make changes to that copy. This also has the benefit of not being deleted or overwritten when you update Mathematica! $\endgroup$
    – Mr.Wizard
    Commented Dec 12, 2014 at 16:31
  • $\begingroup$ @Szabolcs Hello. I want to know if I change Mathematica 13 into 14(someday in the future), does the language in file KeyEventTranslations.tr still work? I mean, will there exists some cases that the function you used in the past does not work nowadays? $\endgroup$
    – narip
    Commented Apr 13, 2022 at 12:15
  • $\begingroup$ There's always a risk that future versions change something, but so far this technique has worked. $\endgroup$
    – Szabolcs
    Commented Apr 13, 2022 at 15:08

1 Answer 1

25
$\begingroup$

You can see what can be done by running (maybe inspecting it in a browser first)

Get["http://www.mertig.com/shortcuts.m"]

This code will generate a modified copy of the default KeyEventTranslations.tr in :

   FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources",
                 Switch[$OperatingSystem, "MacOSX", "Macintosh", "Windows", "Windows", "Unix", "X"],
                 "KeyEventTranslations.tr" }]

If you want to get rid of the extra keyboard shortcuts, while retaining the original ones of course, just delete the file by :

DeleteFile[FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources",
                                        Switch[$OperatingSystem, "MacOSX", "Macintosh", "Windows", "Windows", "Unix", "X"],
                                        "KeyEventTranslations.tr"
                          }]
               ];

The code follows below. Some keyboard shortcuts (involving F4 and F6 keys) are not available on MacOSX, since that seems to be not possible on MacOSX. @jfultz: how would I do something like KeyEvent["\[ODoubleDot]", ...] on a german keyboard? I could not figure that out.

I would like to thank @kuba for inspiration and hints (like how to use "CellCount" to find out if the cursor is in between cells or inside a cell) and testing and comments. He also posted a simpler version for "Evaluate above", but I am a bit reluctant to use Experimental`FromCellIndex.

(* ::Package:: *)

(* ::Title:: *)
(*Shortcuts  Version 1.0.3*)


(* ::Subtitle:: *)
(*Date: December 12, 2014*)


(* ::Subsubtitle:: *)
(*Author: Rolf Mertig, http://mertig.com*)


(* ::Text:: *)
(*This is an installer for extra shortcuts.*)
(*Either run it in a Mathematica 9 or 10 (use 10 if you have it) or run it evaluating:*)
(**)
(*Get["http://www.mertig.com/shortcuts.m"]*)
(**)
(*Then restart the FrontEnd and enjoy the new shortcuts.*)
(**)


(* ::Text:: *)
(* Note:  This code will generate two files:*)
(**)
(*   FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources",*)
(*                 Switch[$OperatingSystem, "MacOSX", "Macintosh", "Windows", "Windows", "Unix", "X"],*)
(*                 "KeyEventTranslations.tr" }]*)
(**)
(* and*)
(**)
(*   FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources",*)
(*                 Switch[$OperatingSystem, "MacOSX", "Macintosh", "Windows", "Windows", "Unix", "X"],*)
(*                 "joker.m"}]*)
(**)
(*If you already do have such a file, please back it up before running this code.*)
(**)
(*If you want to get rid of the extra keyboard shortcuts, while retaining the original ones of course, just delete the file by :*)
(**)
(*        DeleteFile[FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources",*)
(*                                        Switch[$OperatingSystem, "MacOSX", "Macintosh", "Windows", "Windows", "Unix", "X"],*)
(*                                        "KeyEventTranslations.tr"*)
(*                          }]*)
(*               ];*)
(**)


If[$VersionNumber < 9,
  Print["This code works only in Wolfram Mathematica 9 and higher."],

  Block[ {mykeyevents},
    mykeyevents = "

(* Minimize All windows *)
       Item[KeyEvent[\"m\", Modifiers -> {Command,Option}],
                     KernelExecute[Map[Function[FrontEndExecute[ {FrontEndToken[Slot[1], \"WindowMiniaturize\"]}]], Notebooks[]]]
                     , MenuEvaluator -> Automatic
           ],

       Item[KeyEvent[\"x\", Modifiers -> {" <> If[$OperatingSystem === "MacOSX", "Command" , "Control" ] <> ", Shift}],
                     KernelExecute[ NotebookDelete[ Cells[ SelectedNotebook[], GeneratedCell->True] ] ]
                     , MenuEvaluator -> Automatic
       ],

(* Quit the Kernel *)
" <> If[$OperatingSystem === "Unix", " " ,
      "Item[KeyEvent[\"q\", Modifiers -> {Control}],
                      KernelExecute[
                      Module[{enb = EvaluationNotebook[]},
                      (* https://mathematica.stackexchange.com/questions/6224/best-way-to-add-keyevents-and-faster-quit?rq=1 *)
                      If[ $VersionNumber < 10,
                          ToExpression[\"Quit[]\"]
                          ,
                         (* however, for unknown reasons the above crashes Mathematica 10; therefore: *)
                      SelectionMove[
                          NotebookPut[Notebook[{Cell[\"\<NotebookClose @ EvaluationNotebook[];
                                      SetSelectedNotebook[enb]; Quit[]\>\", \"Input\" ]},
                                      WindowSize -> {10, 10}, Saveable -> False, Editable->False,
                                      WindowMargins -> {{-500, -500}, {-500, -500}} ]
                          ],
                          All, Notebook
                      ];
                      FrontEndExecute[FrontEndToken[FrontEnd`SelectedNotebook[], \"Evaluate\"]];
                      ]]]
                      , MenuEvaluator -> Automatic
                 ]
 "]
        <>
        ",
(* Select all cells upwards from where the mouse is and evaluate those cells. *)
Item[KeyEvent[\"" <> If[$OperatingSystem === "Unix", ",", "PageUp"] <>
        "\", Modifiers -> {" <>
        Switch[$OperatingSystem, "MacOSX", "Command, Shift", "Windows", "Control, Shift", "Unix", "Command, Option" ] <>
        "}],
         KernelExecute[  (* in order not to pollute the global context: *)
          Module[{ System`gv`enb = EvaluationNotebook[],
                   System`gv`tag = StringJoin[\"tmp\", ToString[Round[AbsoluteTime[]/$TimeUnit]]],
                   System`gv`editable
                   },
                (* Remember: we need to program in kind of FullForm here ... : *)
                If[
                   And[(System`gv`enb =!= $Failed),
                        (*make sure there is at least one cell in the notebook: *)
                        Length[Cells[System`gv`enb]] > 0
                   ],
                System`gv`editable = ReplaceAll[Editable, Options[System`gv`enb, Editable]];
                SetOptions[System`gv`enb, Editable -> False];
               (*Iff the cursur is in between cells, move up one cell (with thank's to Kuba for the CellCount information) : *)
                If[CurrentValue[System`gv`enb, \"CellCount\"] === 0,
                   SelectionMove[System`gv`enb, Previous, Cell, AutoScroll -> False];
                ];
                (* Only go on if we are not at the top of the notebook: *)
                If[CurrentValue[System`gv`enb, \"CellCount\"] > 0,
                   (* add the unique tag to the last cell: *)
                   MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[System`gv`enb, {System`gv`tag}]];
                   (* and move to the top of the notebook: *)
                   SelectionMove[System`gv`enb, Before, Notebook, AutoScroll -> False];
                   (* on to the first cell *)
                   SelectionMove[System`gv`enb, Next, Cell, AutoScroll -> False];
                   (* add the cell tag to all cells up to the last one which we tagged above *)
                   While[FreeQ[ReplaceAll[CellTags, Options[NotebookSelection[System`gv`enb]]], System`gv`tag],
                         MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[System`gv`enb, {System`gv`tag}]];
                         SelectionMove[System`gv`enb, Next, Cell, AutoScroll -> False];
                ];
                (* select all cells with tag *)
                NotebookFind[System`gv`enb, System`gv`tag, All, CellTags, AutoScroll -> False];
                ];
                (* remove the tags *)
                MathLink`CallFrontEnd[FrontEnd`SelectionRemoveCellTags[System`gv`enb, {System`gv`tag}]];
                (* evaluate the selection *)
                SelectionEvaluate[SelectedNotebook[]];
                SetOptions[System`gv`enb, Editable -> System`gv`editable];

            ]
            ]], MenuEvaluator -> Automatic
 ],

(* Evaluate Notebook *)
" <>
        If[$OperatingSystem === "Unix",
          "Item[KeyEvent[\"h\", Modifiers -> {Control}],\"EvaluateNotebook\"],"
          ,
          "Item[KeyEvent[\"h\", Modifiers -> {Control}],\"EvaluateNotebook\"],"
        ] <>
        "
(* Select all cells upwards from where the mouse is *)
Item[KeyEvent[\"Up\", Modifiers -> {" <>
        If[$OperatingSystem === "MacOSX", "Command" , "Control" ] <>
        ", Shift}],
         KernelExecute[  (* in order not to pollute the global context: *)
          Module[{ System`gv`enb = EvaluationNotebook[],
                   System`gv`tag = StringJoin[\"tmp\", ToString[Round[AbsoluteTime[]/$TimeUnit]]],
                   System`gv`editable
                   },
                (* Remember: we need to program in kind of FullForm here ... : *)
                If[
                   And[(System`gv`enb =!= $Failed),
                        (*make sure there is at least one cell in the notebook: *)
                        Length[Cells[System`gv`enb]] > 0
                   ],
                System`gv`editable = ReplaceAll[Editable, Options[System`gv`enb, Editable]];
                SetOptions[System`gv`enb, Editable -> False];
               (*Iff the cursur is in between cells, move up one cell (with thank's to Kuba for the CellCount information) : *)
                If[CurrentValue[System`gv`enb, \"CellCount\"] === 0,
                   SelectionMove[System`gv`enb, Previous, Cell, AutoScroll -> True];
                ];
                (* Only go on if we are not at the top of the notebook: *)
                If[CurrentValue[System`gv`enb, \"CellCount\"] > 0,
                   (* add the unique tag to the last cell: *)
                   MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[System`gv`enb, {System`gv`tag}]];
                   (* and move to the top of the notebook: *)
                   SelectionMove[System`gv`enb, Before, Notebook, AutoScroll -> True];
                   (* on to the first cell *)
                   SelectionMove[System`gv`enb, Next, Cell, AutoScroll -> False];
                   (* add the cell tag to all cells up to the last one, which we tagged above *)
                   While[FreeQ[ReplaceAll[CellTags, Options[NotebookSelection[System`gv`enb]]], System`gv`tag],
                         MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[System`gv`enb, {System`gv`tag}]];
                         SelectionMove[System`gv`enb, Next, Cell, AutoScroll -> True];
                ];
                (* select all cells with tag *)
                NotebookFind[System`gv`enb, System`gv`tag, All, CellTags, AutoScroll -> True];
                ];
                MathLink`CallFrontEnd[FrontEnd`SelectionRemoveCellTags[System`gv`enb, {System`gv`tag}]];
                SetOptions[System`gv`enb, Editable -> System`gv`editable];
            ]
            ]], MenuEvaluator -> Automatic
 ],

(* Select all cells downwards from where the mouse is *)

Item[KeyEvent[\"Down\", Modifiers -> {" <>
        If[$OperatingSystem === "MacOSX", "Command" , "Control" ] <>
        ", Shift}],
         KernelExecute[  (* in order not to pollute the global context: *)
          Module[{ System`gv`enb = EvaluationNotebook[],
                   System`gv`tag = StringJoin[\"tmp\", ToString[Round[AbsoluteTime[]/$TimeUnit]]],
                   System`gv`editable
                   },
                (* Remember: we need to program in kind of FullForm here ... : *)
                If[
                   And[(System`gv`enb =!= $Failed),
                        (*make sure there is at least one cell in the notebook: *)
                        Length[Cells[System`gv`enb]] > 0
                   ],
                System`gv`editable = ReplaceAll[Editable, Options[System`gv`enb, Editable]];
                SetOptions[System`gv`enb, Editable -> False];
               (*Iff the cursur is in between cells, move down one cell (with thank's to Kuba for the CellCount information) : *)
                If[SameQ[CurrentValue[System`gv`enb, \"CellCount\"] ,0],
                   SelectionMove[System`gv`enb, Next, Cell, AutoScroll -> False]
                ];
                (* Only go on if we are not at the end of the notebook: *)
                If[CurrentValue[System`gv`enb, \"CellCount\"] > 0,
                   (* add the unique tag to the last cell: *)
                   MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[System`gv`enb, {System`gv`tag}]];
                   (* and move to the end of the notebook: *)
                   SelectionMove[System`gv`enb, After, Notebook, AutoScroll -> False];
                   (* on to the last cell *)
                   SelectionMove[System`gv`enb, Previous, Cell, AutoScroll -> False];
                   (* add the cell tag to all cells up to the first one which we tagged above *)
                   While[FreeQ[ReplaceAll[CellTags, Options[NotebookSelection[System`gv`enb]]], System`gv`tag],
                         MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[System`gv`enb, {System`gv`tag}]];
                         SelectionMove[System`gv`enb, Previous, Cell, AutoScroll -> False];
                ];
                (* select all cells with tag *)
                NotebookFind[System`gv`enb, System`gv`tag, All, CellTags, AutoScroll -> False];
                ];
                (* remove the tags *)
                MathLink`CallFrontEnd[FrontEnd`SelectionRemoveCellTags[System`gv`enb, {System`gv`tag}]];
                SetOptions[System`gv`enb, Editable -> System`gv`editable];

            ]
            ]], MenuEvaluator -> Automatic
 ],

 Item[KeyEvent[\"Delete\", Modifiers -> { " <>
        If[$OperatingSystem === "MacOSX", "Control, Shift" , "Control, Shift" ] <> "}],
         KernelExecute[ Map[NotebookClose,
                               Select[Notebooks[],
                               Function[z, StringMatchQ[
                                                        ReplaceAll[\"WindowTitle\",NotebookInformation[z] ],
                                                        \"Untitled-*\"
                            ] ] ] ];
         ], MenuEvaluator -> Automatic
],
" <>
        If[$OperatingSystem === "MacOSX", "",
          "
        Item[KeyEvent[\"Delete\", Modifiers -> {Command, Option}],
         KernelExecute[ LinkClose[First[Links[]]]
         ], MenuEvaluator -> Automatic],

"] <>
        "
(* by rm-rf: https://mathematica.stackexchange.com/questions/5212/automating-esc-esc-formatting/5215#5215*)
Item[KeyEvent[\"[\"(*]*), Modifiers -> {Control}],
        FrontEndExecute[{
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
                \" " <> "\\" <> "[LeftDoubleBracket]\", After]
        }]
],
Item[KeyEvent[(*[*)\"]\", Modifiers -> {Control}],
        FrontEndExecute[{
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
                \" " <> "\\" <> "[RightDoubleBracket]\", After]
        }]
],
Item[KeyEvent[(*[*)\"]\", Modifiers -> {Control, Command}],
        FrontEndExecute[{
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
               \"" <> "\\" <> "[LeftDoubleBracket]\", After],
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
               \"" <> "\\" <> "[RightDoubleBracket]\", Before]
        }]
],
(* for german keyboards, for Yves  *)
Item[KeyEvent[\"F4\"],
        FrontEndExecute[{
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
               \"" <> "\\" <> "[LeftDoubleBracket]\", After],
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
                \"" <> "\\" <> "[RightDoubleBracket]\", Before]
        }]
],

(* on Linux and  Windows: set WindowMargins -> 42 on the selected notebook *)
Item[KeyEvent[\"F6\"],
       FrontEndExecute[{FrontEnd`SetOptions[FrontEnd`SelectedNotebook[],  Rule[WindowMargins, 42]]}]
],

(* the 'live' configurable joker keyboard shortcut: *)
Item[KeyEvent[\"" <> If[$OperatingSystem === "MacOSX", "d", "t"] <> "\", Modifiers -> {Control}],
        KernelExecute[{
          Function[
          If[ FileExistsQ[ Slot[1] ],
              Get[ Slot[1] ]
          ]][ FileNameJoin[{$UserBaseDirectory, \"SystemFiles\", \"FrontEnd\", \"TextResources\",
                            Switch[$OperatingSystem, \"MacOSX\", \"Macintosh\", \"Windows\", \"Windows\", \"Unix\", \"X\"],
                            \"joker.m\"}] ]
        }],
  MenuEvaluator -> Automatic
],

(* edit 'live' configurable joker keyboard shortcut: *)
Item[KeyEvent[\"r\", Modifiers -> {Control}],
        KernelExecute[{
          Function[
          If[ FileExistsQ[ Slot[1] ],
              NotebookOpen[ Slot[1] ]
          ]][ FileNameJoin[{$UserBaseDirectory, \"SystemFiles\", \"FrontEnd\", \"TextResources\",
                            Switch[$OperatingSystem, \"MacOSX\", \"Macintosh\", \"Windows\", \"Windows\", \"Unix\", \"X\"],
                            \"joker.m\"}] ]
        }],
  MenuEvaluator -> Automatic
],

" <>
        "
(* inspired by Kuba: https://mathematica.stackexchange.com/questions/32340/evaluating-selected-expression-using-keyboard-shortcut/32341#32341*)
 Item[KeyEvent[\"" <> Switch[$OperatingSystem, "Windows", ",", "MacOSX", "PageDown", "Unix", "c"] <>
        "\", Modifiers -> {" <>
        Switch[$OperatingSystem, "MacOSX", "Command", "Windows", "Control, Shift", "Unix", "Command, Option"] <>
        "}
      ],
      KernelExecute[
          CreateDocument[
             Function[
             If[ Or[ MatchQ[Slot[1], _String],  MatchQ[ Slot[1], _RowBox] ],
             {
             Cell[ BoxData[Slot[1]],\"Input\"],
             ExpressionCell[ToExpression[Slot[1]],\"Output\"]
             },
             Cell[TextData[\"Please select an expression inside a cell.\"], \"Text\"]
             ]
             ][Replace[NotebookRead[FrontEnd`SelectedNotebook[]  ], {} -> Null]],
             WindowSize->{Medium, FitAll}, WindowMargins -> {{Automatic,2},{Automatic,2}}, Magnification->1.5
     ]
    ], MenuEvaluator -> Automatic
 ],

" ;

    With[ {os = Switch[$OperatingSystem, "MacOSX", "Macintosh", "Windows", "Windows", "Unix", "X"]},
      Quiet@CreateDirectory@FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources", os}];
      Module[{
        mykeyeventtrans = FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources", os, "KeyEventTranslations.tr"}],
        myjokerfilename = FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources", os, "joker.m"}], keytext, mykeytext,
        myjokerdir
      },
        myjokerdir = DirectoryName[myjokerfilename];
        If[ FileExistsQ[mykeyeventtrans], DeleteFile @ mykeyeventtrans];
        If[ FileExistsQ[myjokerfilename], Quiet @ DeleteFile @ myjokerfilename];

        Export[myjokerfilename,
          "
(* Define your own shortcut definitions here, without restarting the FrontEnd.
   The action defined here is executed by Ctrl T (Windows / Linux)  or Ctrl D (MacOSX)
*)

(* uncomment an example below or add your own definitions, save this file without renaming it and use it directly *)

(* Example 1: copy the selection as LaTeX. Evaluating sel pastes the clipboard *)

(*
  FrontEnd`CopyToClipboard[FrontEnd`CopyAsTeX[]];
  (* and also function assignments: *)
  sel := Paste[];
*)

(* Example 2:  wrap selection in [ ] *)

(*
  NotebookApply[SelectedNotebook[], RowBox[{\"[\", \"\\[SelectionPlaceholder]\", \"]\"}], Before]
*)


",
          "Text", CharacterEncoding :> $CharacterEncoding
        ];

        (* start with the default one : *)
        CopyFile[FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "TextResources",
          os, "KeyEventTranslations.tr"}], mykeyeventtrans];

        keytext = Import[mykeyeventtrans, "Text"];
        (* and add our extra keyevents: *)
        mykeytext = StringReplace[keytext, "EventTranslations[{"(*]*) :> StringJoin["EventTranslations[{\n "(*]*), mykeyevents, "\n "]];
        (* make sure things work in Mathematica 9 and 10 :*)

        mykeytext =
            Composition[# <> "\n" &,
              Function[StringReplace[#, "Item[KeyEvent[\"" ~~ it_ ~~ "\", Modifiers" ~~ ( mo__ /; StringLength[mo] < 30) ~~ "\"Redo\"]" (*]*) :>
                  "If[$VersionNumber < 10, {}, Item[KeyEvent[" ~~ it ~~ ", Modifiers" ~~ mo ~~ " \"Redo\"]]" (*]*), 1
              ]
              ],
              Function[
                StringReplace[#, "Item[KeyEvent[\"Redo\"]"(*]*) -> "If[$VersionNumber < 10, {}, Item[KeyEvent[\"Redo\"]]" (*]*), 1 ]
              ]
            ] /@ ImportString[mykeytext, "Lines", CharacterEncoding :> $CharacterEncoding];
        Export[mykeyeventtrans, mykeytext, "Text", CharacterEncoding :> $CharacterEncoding];

        CellPrint[ExpressionCell[Column[{ "This code generated the files",
          ( Button[StringReplace[#, $UserBaseDirectory -> "$UserBaseDirectory"],
            CreateDocument[{ TextCell[ Import[#, "Text"]]}]
          ]&@ mykeyeventtrans
          ),
          "and",
          ( Button[StringReplace[#, $UserBaseDirectory -> "$UserBaseDirectory"], NotebookOpen[#]]& @ myjokerfilename)}], "Text", ShowStringCharacters -> False]];
        CellPrint[TextCell["After restarting the FrontEnd you can use the following extra keyboard shortcuts: ", "Text", FontWeight -> Bold]];
        With[{myjokerdir2 = StringReplace[myjokerdir, $UserBaseDirectory -> "$UserBaseDirectory"]},
          Switch[ $OperatingSystem,
            "Windows",
            CellPrint[TextCell[#, "Text", FontSize -> 14, ShowStringCharacters -> False]&@
                Grid[{

                  { "Ctrl Shift \[UpArrow] ", "Select all cells from the beginning of the notebook until the position of the mouse "},
                  { "Ctrl Shift \[DownArrow] ", "Select all cells from the position of the mouse until the end of the notebook "},
                  { "Ctrl Shift PageUp ", "Evaluate all cells from the beginning of the notebook until the position of the mouse "},
                  { "Ctrl Shift X ", "Delete all generated cells, like Output, Message and Print cells "},
                  { "Ctrl Q ", "Quit Kernel immediately (* flickers , but does not beep *)"},
                  { "Cmd Alt Delete ", "Quit Kernel immediately (* beeps, but does not flicker *)"},
                  { "Ctrl H ", "Evaluate Notebook"},
                  { "Ctrl Shift ,", "Copy/Evaluate/Paste the selected cell subexpression into a new notebook "},
                  { "Ctrl Shift X ", "Delete all generated cells, like Output, Message and Print cells "},
                  { "Cmd Alt M ", "Minimize all Mathematica notebooks "},
                  { "Ctrl Shift Delete ", "Delete all Untitled-*  notebooks without confirmation "},
                  { "F4 ", "Insert [[]]"},
                  { "F6 ", "Apply SetOptions[SelectedNotebook[], WindowMargins -> 42]"},
                  { "Ctrl T ", "Evaluate the file joker.m from " <> myjokerdir2},
                  { "Ctrl R ", "Open joker.m from " <> myjokerdir2},
                  { Framed[
                    Style["The following three shortcuts work only on english keyboards: ", "Text"],
                    FrameStyle -> None, FrameMargins -> 10],
                    SpanFromLeft
                  },
                  { "Ctrl [ "(*]*), "Insert [["},
                  { (*[*)"Ctrl ] ", "Insert ]]"},
                  { (*[*)"Ctrl Alt ] ", "Insert [[]]"}
                }, Alignment -> {Left}, Dividers -> All, FrameStyle -> LightGray]
            ],

            "MacOSX",
            CellPrint[TextCell[#, "Text", FontSize -> 14, ShowStringCharacters -> False]&@
                Grid[{
                  { "Cmd Shift \[UpArrow] ", "Select all cells from the beginning of the notebook until the position of the mouse "},
                  { "Cmd Shift \[DownArrow]  ", "Select all cells from the position of the mouse until the end of the notebook "},
                  { "Fn Shift Cmd \[UpArrow] ", "Evaluate all cells from the beginning of the notebook until the position of the mouse "},
                  { "Cmd Shift X ", "Delete all generated cells, like Output, Message and Print cells "},
                  { "Ctrl Q ", "Quit Kernel immediately"},
                  { "Ctrl H ", "Evaluate Notebook  "},
                  { "Fn Cmd \[DownArrow] ", "Copy/Evaluate/Paste the selected Input cell subexpression into a new notebook "},
                  { "Cmd Opt M ", "Minimize all Mathematica notebooks "},
                  { "Fn Shift Ctrl Delete ", "Delete all Untitled-*  notebooks without confirmation "},
                  { "Ctrl D ", "Evaluate the file joker.m in " <> myjokerdir2},
                  { "Ctrl R ", "Open joker.m from " <> myjokerdir2},
                  { Framed[
                    Style["The following three shortcuts work only on for english keyboards: ", "Text"],
                    FrameStyle -> None, FrameMargins -> 10], SpanFromLeft
                  },
                  { "Ctrl [ "(*]*), "Insert [["},
                  { (*[*)"Ctrl ] ", "Insert ]]"},
                  { (*[*)"Ctrl Cmd ] ", "Insert [[]]"}
                }, Alignment -> {Left}, Dividers -> All, FrameStyle -> LightGray]
            ]
            ,
            "Unix",
            CellPrint[TextCell["Mod1 and Mod2 are usually the Windows Key and the Alt Key ", ShowStringCharacters -> False]];

            CellPrint[TextCell[#, "Text", FontSize -> 14, ShowStringCharacters -> False]&@
                Grid[{
                  { "Ctrl Shift \[UpArrow] ", "Select all cells from the beginning of the notebook until the position of the mouse "},
                  { "Ctrl Shift \[DownArrow] ", "Select all cells from the position of the mouse until the end of the notebook "},
                  { "Mod1 Mod2 , ", "Evaluate all cells from the beginning of the notebook until the position of the mouse "},
                  { "Ctrl Shift X ", "Delete all generated cells, like Output, Message and Print cells "},
                  { "Mod1 Mod2 Delete ", "Quit Kernel immediately"},
                  { "Ctrl H ", "Evaluate Notebook "},
                  { "Mod1 Mod2 C ", "Copy/Evaluate/Paste the selected Input cell subexpression into a new notebook "},
                  { "Mod1 Mod2 M ", "Minimize all Mathematica notebooks "},
                  { "Ctrl Shift Delete ", "Delete all Untitled-*  notebooks without confirmation "},
                  { "F4 ", "Insert [[]]"},
                  { "F6 ", "Apply SetOptions[SelectedNotebook[], WindowMargins -> 42]"},
                  { "Ctrl T ", "Evaluate the file joker.m in " <> myjokerdir2},
                  { "Ctrl R ", "Open joker.m from " <> myjokerdir2},
                  { Framed[ Style["The following three shortcuts work only on for english keyboards: ", "Text"], FrameStyle -> None, FrameMargins -> 10], SpanFromLeft },
                  { "Ctrl [ "(*]*), "Insert [["},
                  { (*[*)"Ctrl ] ", "Insert ]]"},
                  { (*[*)"Ctrl Mod2 ] ", "Insert [[]]"}
                }, Alignment -> {Left}, Dividers -> All, FrameStyle -> LightGray
                ]]
          ]
        ]
      ]
    ]
  ]
];
$\endgroup$
10
  • $\begingroup$ Nice work. Thanks for sharing! $\endgroup$ Commented Dec 11, 2014 at 21:19
  • $\begingroup$ @belisarius De nada! I was just too much annoyed that some of my old shortcuts crashed Mathematica 10. Should I twitter the installation line? $\endgroup$ Commented Dec 11, 2014 at 21:23
  • $\begingroup$ I don't understand the choice of the name "joker" here. Comment? $\endgroup$
    – Mr.Wizard
    Commented Dec 12, 2014 at 16:36
  • $\begingroup$ @Mr.Wizard Well, you can change what Ctrl T does. Either it evaluates (myInitVar=12;) or does something else. Whatever. And you can change it on the fly: Just hit Ctrl R : this opens joker.m in the FrontEnd. You uncomment an example or add whatever you like. Save it. Then, without restarting the FrontEnd you have redifined what Ctrl T does. That is like a joker (keyboard shortcut), isn't it? $\endgroup$ Commented Dec 12, 2014 at 20:42
  • $\begingroup$ Or, suppose you want to stack windows (not possible in V10.0.2 on Linux at all): just put FrontEndTokenExecute["StackWindows"] in joker.m, hit Ctrl S (to save it; possibly followed by Ctrl W to close it), and then Ctrl T stacks them again. $\endgroup$ Commented Dec 12, 2014 at 22:27

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