Skip to content

Instantly share code, notes, and snippets.

@mrmanc
Last active May 4, 2023 04:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrmanc/72eb1712472242e8962661f59ea60ca8 to your computer and use it in GitHub Desktop.
Save mrmanc/72eb1712472242e8962661f59ea60ca8 to your computer and use it in GitHub Desktop.
Turn off annoying macOS man page shortcuts via the command line

Turn off annoying macOS man page shortcuts via the command line

Context

macOS 10.14.4 introduced a keyboard shortcut that conflicts with one of IntelliJ IDEA’s best shortcuts. cmd-shift-a pops open a Terminal window running an apropos search on the text selection, rather than the command palette.

You can manually disable these keyboard shortcuts via System Preferences, but this script does this programmatically. I was unable to find any existing information about how to do this via the command line, so I rolled my own solution.

It took a long time to work out which defaults domain to find the plist for this. I probably worked out the pbs domain from this post.

Solution

TEMP_SETTINGS_FILE=$(mktemp -t 'man-shortcuts-off.json')
cat > $TEMP_SETTINGS_FILE <<EOF
{
  "NSServicesStatus": {
    "com.apple.Terminal - Open man Page in Terminal - openManPage": {
      "presentation_modes": {
        "ContextMenu": false,
        "ServicesMenu": false
      },
      "enabled_context_menu": false,
      "enabled_services_menu": false
    },
    "com.apple.Terminal - Search man Page Index in Terminal - searchManPages": {
      "presentation_modes": {
        "ContextMenu": false,
        "ServicesMenu": false
      },
      "enabled_context_menu": false,
      "enabled_services_menu": false
    }
  }
}
EOF
# Settings are stored in the pbs domain. Other settings in this domain will not be overwritten. I’ve included the settings to change in JSON for brevity. They are converted to XML (which `defaults import` expects) before being imported.
plutil -convert xml1 -o - ${TEMP_SETTINGS_FILE} | defaults import pbs -
rm ${TEMP_SETTINGS_FILE}
@davestewart
Copy link

Nice! Just seen this after coming across your comment on the JetBrains blog.

@mrmanc
Copy link
Author

mrmanc commented Apr 25, 2022

Nice! Just seen this after coming across your comment on the JetBrains blog.

Excellent… pleased to have helped! Out of interest, was this more useful than being able to do it using System Preferences for your machine?

@davestewart
Copy link

davestewart commented Apr 25, 2022

I'd already done it TBH. But good knowledge for you to solve bigger problems in future eh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment