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.

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Script to set the 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.

Adjust Key repeat rate with the help of a script to configure Keyboard settings on Mac

Script to set the delay until repeat

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.

Adjust Delay until repeat with the help of the script to configure Keyboard settings on Mac

Script to enable Keyboard navigation

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.

Turn on Keyboard navigation with the help of a script to configure Keyboard settings on Mac

Notes:

This script works only on devices running macOS 13.0 and above.

Script to disable auto correct

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:

  • System Settings > Keyboard > Text Input > Edit on macOS versions 13.0 and above.
  • System Preferences > Keyboard > Text on macOS versions below 13.0.
  • Turn off Auto correct with the help of a script to configure Keyboard settings on Mac

    Notes:

    • The changes made by the script will only become effective after you log out of the device and then log back in.
    • It is recommended to manually validate the script execution on a system before executing the action in bulk.
    • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository