Category filter
Script to configure keyboard settings on Mac
This doc provides scripts to configure keyboard settings on a Mac. Learn how to configure settings for Keyboard navigation, Key repeat rates, auto-correct, and more, suiting the user requirements.
For instance, enabling keyboard navigation allows users to efficiently use keyboard shortcuts for tasks typically done with a mouse, such as navigating menus, selecting items, and interacting with windows and dialogues. Adjusting the key repeat rate for a keyboard based on where the device is deployed is important. The scripts provided below help you perform such keyboard customization settings on a Mac that can be executed using the “Execute Custom Script” action.
Script to set the key repeat rate
1 2 3 4 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults write -g KeyRepeat -int <key_repeat_rate> |
The “Key repeat rate” on macOS refers to the speed at which a character is repeatedly registered when a key is held down on a keyboard.
The provided script retrieves the current user and user ID on macOS, then uses launchctl to run the command that adjusts the Key repeat rate using the “KeyRepeat” key. Users can set the desired Key repeat rate (between 1-15) by replacing <key_repeat_rate> in the script with their preferred value. The changes will be reflected in System Settings or System Preferences under Keyboard settings.
Script to set the delay until repeat
1 2 3 4 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults write -g InitialKeyRepeat -int <key_delay> |
The “Delay until repeat” setting on macOS refers to the amount of time your keyboard waits before it starts repeating a key when you hold it down.
The provided script for macOS retrieves the current user and user ID, then utilizes launchctl to execute a command that adjusts the key delay until repeat using the “InitialKeyRepeat” key. Users can customize the key delay by replacing <key_delay> with a value between 0-3 in the script. The changes will be reflected in System Settings or System Preferences under Keyboard settings.
Script to enable Keyboard navigation
1 2 3 4 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults write NSGlobalDomain AppleKeyboardUIMode -int 3 |
The provided script retrieves the current user and their user ID on macOS and then utilizes launchctl to enable keyboard navigation by setting the AppleKeyboardUIMode key to 3 in the NSGlobalDomain. The Keyboard navigation option will be enabled in System Settings under Keyboard settings.
Script to disable auto correct
1 2 3 4 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false |
The provided script retrieves the current user and their user ID on macOS. It then uses launchctl to disable auto-correct by setting the NSAutomaticSpellingCorrectionEnabled key to false in the NSGlobalDomain. NSGlobalDomain is a domain in macOS used to store default system settings that affect all applications running on the system.
The Correct Spelling Automatically option will be disabled in: