16

I have been trying to figure this out for a long time. I have a pretty typical Mac OS provisioning script:

https://gist.github.com/ryanpcmcquen/b2e608311f286a4ab3e1

I would like to change the Mission control shortcuts to all be Ctrl+Alt+... instead of Ctrl+.... For example, the default is: Ctrl+Up to activate Mission Control. I would like to change this to Ctrl+Alt+Up, because the current shortcut conflicts with other programs I use.

Note that I am already aware of how to do this through System Preferences > Keyboard > Shortcuts, I am looking for a scriptable, command line solution.

EDIT: Thanks to @user3439894 I went through and made a script to change all the plist keys to what I want them to be. The only issue is, it does not work. :-(

Here is what I have so far:

#!/bin/bash
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 32 "{enabled = 1; value = { parameters = (65535, 126, 2883584); type = standard; }; }"
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 33 "{enabled = 1; value = { parameters = (65535, 125, 2883584); type = standard; }; }"
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 34 "{enabled = 1; value = { parameters = (65535, 126, 3014656); type = standard; }; }"
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 35 "{enabled = 1; value = { parameters = (65535, 125, 3014656); type = standard; }; }"
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 79 "{enabled = 1; value = { parameters = (65535, 123, 2883584); type = standard; }; }"
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 80 "{enabled = 1; value = { parameters = (65535, 123, 3014656); type = standard; }; }"
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 81 "{enabled = 1; value = { parameters = (65535, 124, 2883584); type = standard; }; }"
defaults write ~/Library/Preferences/com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 82 "{enabled = 1; value = { parameters = (65535, 124, 3014656); type = standard; }; }"
chown -Rf `whoami` ~/Library/Preferences/com.apple.symbolichotkeys.plist;
defaults read com.apple.symbolichotkeys
7
  • Did you ever figure out a solution for this?
    – Nathan
    Commented Dec 2, 2018 at 12:48
  • @Nathan, nope. I just roll with the defaults now. Commented Dec 3, 2018 at 13:59
  • I had a similar issue. Maybe you can try my solution: apple.stackexchange.com/questions/344494/…
    – Nathan
    Commented Dec 3, 2018 at 14:01
  • @Nathan, it looks like your solution requires manual intervention. I just learned how to change the other programs I use to have different hotkeys. Hammerspoon FTW. Commented Dec 3, 2018 at 14:04
  • This portion of the command type = standard; should actually be type = 'standard'; note the quotes around 'standard'. That said though, sometimes even with a properly formed command line the change just does not take effect, even with ; killall -u $USER cfprefsd added to the end of the defaults command. Also the full path to the .plist file in this use case is not necessary and simply e.g. defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys ... and the remainder of the command is all that's necessary. Commented Aug 15, 2019 at 19:34

3 Answers 3

6

This is not a direct answer although I hope the information presented herein will help you get to a direct answer.

I can tell you what changes in which file when you change the default keyboard shortcut for Mission Control from Control-Up Arrow to Control-Option-Up Arrow. It's the "Item 2 Number" of the "parameters" Array in the "value" Dictionary of the "32" Dictionary and "34" Dictionary of the "AppleSymbolicHotKeys" Dictionary in the /Users/$USER/Library/Preferences/com.apple.symbolichotkeys.plist file.

Here's a defaults read representation of the com.apple.symbolichotkeys.plist file structure as it relates to the changes made under the defined circumstances above.

Mission Control with the default of Control-Up Arrow

{
    AppleSymbolicHotKeys =     {
        32 =         {
            enabled = 1;
            value =             {
                parameters =                 (
                    65535,
                    126,
                    2359296
                );
                type = standard;
            };
        };
        34 =         {
            enabled = 1;
            value =             {
                parameters =                 (
                    65535,
                    126,
                    2490368
                );
                type = standard;
            };
        };
    };
}

Mission Control changed to Control-Option-Up Arrow

{
    AppleSymbolicHotKeys =     {
        32 =         {
            enabled = 1;
            value =             {
                parameters =                 (
                    65535,
                    126,
                    2883584
                );
                type = standard;
            };
        };
        34 =         {
            enabled = 1;
            value =             {
                parameters =                 (
                    65535,
                    126,
                    3014656
                );
                type = standard;
            };
        };
    };
}

The BUGS section of the defaults man page says:

Defaults can be structured in very complex ways, making it difficult for the user to enter them with this command.

And this is a perfect example as it will be a very complex command line using defaults to write the target values to the target array elements, if it's even doable. Just an FYI... If you're going to attempt to do a defaults write com.apple.symbolichotkeys ... command make sure you've backed up the target file first.

The other option is to use an AppleScript to change the settings by navigating the System Preferences GUI and that too will be a little complex in comparison to setting a top level object, which the target here is not. I'm not even sure it's doable however if I needed an automated way then I'd figure it out however I do no have the time to figure out either method, sorry.

At least you now know what changes where and from there you may be able to either figure it out on your own or get additional help with knowing this little bit more.

Here's a clipped image in Xcode of the com.apple.symbolichotkeys.plist file.

enter image description here

BTW I trapped the changes using a third party utility that logged the filesystem changes and then converted that information to a more human readable output to provide this information.

6
  • It does seem to change the proper plist files, the only issue is, the shortcuts do not actually change, not after reboots, re-reading the file, or anything. Commented Aug 25, 2015 at 18:39
  • What's the name of this "third party utility that logged the filesystem changes and then converted that information to a more human readable output"? Commented May 12, 2016 at 15:18
  • 1
    @Allen Bargi, IIRC It was probably filemon which was part of the Extras from the book "Mac OS X Internals - To The Apple's Core" in the form of source code filemon.c which I compiled to an executable on my system. I then compared the differences in the changed file of its current state against the file from a Time Machine backup made just before the changes. You can also use the native fs_usage command. Commented May 12, 2016 at 16:00
  • @ryanpcmcquen your link is broken Commented Aug 14, 2019 at 22:29
  • @charlesreid1, oh well, it didn't work. Commented Aug 15, 2019 at 19:08
0

This is my recommendation: use a utility such as Karabiner to accompish such customization.

As a developer, I want to say that personally I find it to be a fascinating and tantalizing issue, and it really showcases the uglier, darker side of macOS skulking behind the scenes which only software devs and hackers can truly appreciate...

The problem is simple enough: I just want to remap the default key combination to my own binding.

Why on earth is it so difficult/complicated? I intend to find out and post a solution... Stay tuned.

1
  • Thank you, I look forward to seeing what you find out. But downloading an external program takes as long as setting them through the Mac's standard interfaces, I am still hoping for a built-in command line solution. Commented Nov 9, 2016 at 23:51
0

I was trying to do a similar thing and stumbled across plutil. I successfully disabled the ^→ and ^← commands (for switching spaces) using the following:

plutil -replace AppleSymbolicHotKeys.79.enabled -bool NO ~/Library/Preferences/com.apple.symbolichotkeys.plist
plutil -replace AppleSymbolicHotKeys.80.enabled -bool NO ~/Library/Preferences/com.apple.symbolichotkeys.plist
plutil -replace AppleSymbolicHotKeys.81.enabled -bool NO ~/Library/Preferences/com.apple.symbolichotkeys.plist
plutil -replace AppleSymbolicHotKeys.82.enabled -bool NO ~/Library/Preferences/com.apple.symbolichotkeys.plist

A bit of tinkering and it'd probably be simple enough to modify this to change the keybindings rather than unbinding them.

Haven't found a way to get these to apply without restarting though.

1
  • 2
    You can run /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u to read and activate settings that have been modified in permanent storage. Commented Nov 28, 2022 at 6:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .