4
$\begingroup$

Style shortcuts are mapped to keys like Cmd+1/Cmd+2 which conflicts with MacOS spaces switching. Can someone suggest how to remap them to Alt+1/Alt+2/etc.?

Keyboard translations file for Mac is in /Applications/Mathematica.app/Contents/SystemFiles/FrontEnd/TextResources/Macintosh/KeyEventTranslations.tr

However, Alt+1 and Alt+Shift+1 are already captured by macos, and I couldn't get Cmd+Shift+1 mapped to anything (something else captures it?), it turned out easier to change MacOS shortcuts (System Preferences/Keyboard/Shortcuts) to free up Cmd+1 rather than changing Mathematica defaults

$\endgroup$
3
  • $\begingroup$ I use OSX as well, and my suggestion worked for me. You need to restart Mathematica to see the changes though. Perhaps you didn't do that? $\endgroup$
    – Carl Woll
    Apr 23, 2017 at 19:52
  • $\begingroup$ do I need to evaluate the SetOptions command every time I start mathematica? $\endgroup$ Apr 23, 2017 at 20:14
  • $\begingroup$ You just need to use a stylesheet where you assign MenuCommandKey->None to relevant styles, and then save the notebook with that stylesheet. $\endgroup$
    – Carl Woll
    Apr 23, 2017 at 20:20

1 Answer 1

4
$\begingroup$

You can eliminate the style key bindings by setting MenuCommandKey->None for the existing styles. For example, if you evaluate:

SetOptions[
    EvaluationNotebook[],
    StyleDefinitions->Notebook[
        {
        Cell[StyleData[StyleDefinitions->"Default.nb"]],
        Cell[StyleData["Title"],MenuCommandKey->None],
        Cell[StyleData["Chapter"],MenuCommandKey->None]
        },
        WindowSize->{808,689},
        WindowMargins->{{38,Automatic},{-80,Automatic}},
        Visible->False,
        FrontEndVersion->"11.1 for Mac OS X x86 (32-bit, 64-bit Kernel) (January 4, 2017)",
        StyleDefinitions->"PrivateStylesheetFormatting.nb"
    ]
]

the bindings for Cmd+1 and Cmd+2 should be gone. You can also use MenuCommandKey->key to change to a different Cmd+key combination, but care must be taken to avoid conflicts with key bindings defined in the menu system.

If you want to change the binding to something like Alt+1, you could edit KeyEventTranslations.tr. An example of a key binding that can be added:

    Item[KeyEvent["1", Modifiers -> {Option}], "Style" -> "Title"]

I believe the precedence for key bindings is:

MenuSetup.tr > KeyEventTranslations.tr > Operating System
$\endgroup$
3
  • $\begingroup$ Can you give some hints on what specifically to add to KeyEventTranslations.tr for this? $\endgroup$
    – Szabolcs
    Apr 6, 2017 at 8:37
  • $\begingroup$ @Szabolcs I added an example. $\endgroup$
    – Carl Woll
    Apr 6, 2017 at 15:52
  • $\begingroup$ so, in the end "Alt+1" and "Shift+Alt+1" are getting intercepted by Mac to make funny characters, and "Shift+Cmd+1" is intercepted by something (I can't map anything to it through KeyEventTranslations.tr), the simplest thing in the end ended up being to change my MacOS bindings for switching spaces and keep Mathematica defaults $\endgroup$ Apr 23, 2017 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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