# 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](https://www.hexnode.com/mobile-device-management/help/how-to-run-scripts-on-mac-using-hexnode-mdm/)” action.

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

 

Script to set the key repeat rate 
----------------------------------

Script to set the key repeat rate on Mac

\#!/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> 

   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.

[![Adjust Key repeat rate with the help of a script to configure Keyboard settings on Mac](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Set-Key-repeat-rate-using-script-to-configure-Keyboard-settings-on-Mac.png "Set Key repeat rate using script to configure Keyboard settings on Mac")](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Set-Key-repeat-rate-using-script-to-configure-Keyboard-settings-on-Mac.png)

Script to set the delay until repeat 
-------------------------------------

Script to set the delay until repeat on Mac

\#!/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> 

   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.

[![Adjust Delay until repeat with the help of the script to configure Keyboard settings on Mac](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Set-Delay-until-repeat-using-script-to-configure-Keyboard-settings-on-Mac.png "Set Delay until repeat using script to configure Keyboard settings on Mac")](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Set-Delay-until-repeat-using-script-to-configure-Keyboard-settings-on-Mac.png)

Script to enable Keyboard navigation 
-------------------------------------

Script to enable Keyboard navigation on Mac

\#!/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 

   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.

[![Turn on Keyboard navigation with the help of a script to configure Keyboard settings on Mac](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Enable-Keyword-navigation-using-script-to-configure-Keyboard-settings-on-Mac.png "Enable Keyword navigation using script to configure Keyboard settings on Mac")](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Enable-Keyword-navigation-using-script-to-configure-Keyboard-settings-on-Mac.png)

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

 

Script to disable auto correct 
-------------------------------

Script to disable auto correct on Mac

\#!/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 

   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:

- **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](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Disable-Auto-correct-using-script-to-configure-keyboard-settings-on-Mac.png "Disable Auto correct using script to configure keyboard settings on Mac")](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/07/Disable-Auto-correct-using-script-to-configure-keyboard-settings-on-Mac.png)

 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.