Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard preferences have little effect #1

Open
simonaertssen opened this issue May 2, 2021 · 0 comments
Open

Keyboard preferences have little effect #1

simonaertssen opened this issue May 2, 2021 · 0 comments

Comments

@simonaertssen
Copy link

Hi there, I am writing a bash script to switch between my native and external keyboard. It happens a lot that I need to take my laptop somewhere and I forget to change the keyboards manually. I have a native French keyboard (AZERTY) and an external US International keyboard (QWERTY). You see, the French native was a mistake...

I stumbled upon your Keyboard Preferences in

dotfiles/bin/macos-system-defaults.sh, lines 100 - 112

Let's say I want to switch to the native keyboard, which is a French-numerical layout with ID 1111. Therefore I run:

defaults write ~/Library/Preferences/com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID "com.apple.keylayout.French-numerical"
defaults write ~/Library/Preferences/com.apple.HIToolbox AppleDefaultAsciiInputSource -dict InputSourceKind "Keyboard Layout" "KeyboardLayout ID" -int 1111 "KeyboardLayout Name" French-numerical

# Delete the default layouts
defaults delete ~/Library/Preferences/com.apple.HIToolbox AppleEnabledInputSources

# Enable French-numerical layout
defaults write ~/Library/Preferences/com.apple.HIToolbox AppleEnabledInputSources -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 1111; "KeyboardLayout Name" = French-numerical; }'
defaults write ~/Library/Preferences/com.apple.HIToolbox AppleInputSourceHistory -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 1111; "KeyboardLayout Name" = French-numerical; }'
defaults write ~/Library/Preferences/com.apple.HIToolbox AppleSelectedInputSources -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 1111; "KeyboardLayout Name" = French-numerical; }'

I can check this simply with

defaults read ~/Library/Preferences/com.apple.HIToolbox
{
    AppleCurrentKeyboardLayoutInputSourceID = "com.apple.keylayout.French-numerical";
    AppleDefaultAsciiInputSource =     {
        InputSourceKind = "Keyboard Layout";
        "KeyboardLayout ID" = 1111;
        "KeyboardLayout Name" = "French-numerical";
    };
    AppleDictationAutoEnable = 1;
    AppleEnabledInputSources =     (
                {
            InputSourceKind = "Keyboard Layout";
            "KeyboardLayout ID" = 1111;
            "KeyboardLayout Name" = "French-numerical";
        }
    );
    AppleGlobalTextInputProperties =     {
        TextInputGlobalPropertyPerContextInput = 0;
    };
    AppleInputSourceHistory =     (
                {
            InputSourceKind = "Keyboard Layout";
            "KeyboardLayout ID" = 1111;
            "KeyboardLayout Name" = "French-numerical";
        }
    );
    AppleSelectedInputSources =     (
                {
            InputSourceKind = "Keyboard Layout";
            "KeyboardLayout ID" = 1111;
            "KeyboardLayout Name" = "French-numerical";
        }
    );
}

However, when I am pressing keys, the keyboard is still on QWERTY, the US layout. And I do get the same error (no layout switch) when I just use your code and try to set the keyboard layout to Finnish. Any ideas?

My laptop is a MacBook Pro (2015) running macOS Mojave 10.14.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant