Skip to content

Instantly share code, notes, and snippets.

@cemlyn007
Last active March 20, 2025 03:00
Show Gist options
  • Save cemlyn007/f91af001618816ec99bd0d58a020714e to your computer and use it in GitHub Desktop.
Save cemlyn007/f91af001618816ec99bd0d58a020714e to your computer and use it in GitHub Desktop.
MacOS apply keyboard settings and change scroll without restart
#!/bin/sh
set -e
# Function to check if key 118 is enabled (used as a state indicator)
is_windows_mode() {
current_state=$(defaults read com.apple.symbolichotkeys AppleSymbolicHotKeys | grep -A5 '"118" =' | grep "enabled" | grep -c "0")
[ "$current_state" -eq 1 ]
}
# Function to toggle between Mac and Windows keyboard settings
toggle_keyboard_mode() {
if is_windows_mode; then
apply_mac_settings
else
apply_windows_settings
fi
}
# Apply Mac keyboard settings with full parameter structures
apply_mac_settings() {
echo "Applying settings for Mac mode..."
# Key 118 - Spotlight
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 118 \
'<dict>
<key>enabled</key>
<true/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>18</integer>
<integer>262144</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 32 - Mission Control - Up
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 32 \
'<dict>
<key>enabled</key>
<true/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>126</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 33 - App Windows - Down
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 33 \
'<dict>
<key>enabled</key>
<true/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>125</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 79 - Move left a space
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 79 \
'<dict>
<key>enabled</key>
<true/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>123</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 81 - Move right a space
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 81 \
'<dict>
<key>enabled</key>
<true/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>124</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Set reversed scroll direction (Windows style)
defaults write -g com.apple.swipescrolldirection -bool YES
echo "✅ Mac keyboard settings applied successfully."
}
# Apply Windows keyboard settings with full parameter structures
apply_windows_settings() {
echo "Applying settings for Windows mode..."
# Key 118 - Spotlight
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 118 \
'<dict>
<key>enabled</key>
<false/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>18</integer>
<integer>262144</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 32 - Mission Control - Up
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 32 \
'<dict>
<key>enabled</key>
<false/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>126</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 33 - App Windows - Down
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 33 \
'<dict>
<key>enabled</key>
<false/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>125</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 79 - Move left a space
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 79 \
'<dict>
<key>enabled</key>
<false/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>123</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Key 81 - Move right a space
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 81 \
'<dict>
<key>enabled</key>
<false/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>124</integer>
<integer>8650752</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>'
# Set natural scroll direction (Mac style)
defaults write -g com.apple.swipescrolldirection -bool NO
echo "✅ Windows keyboard settings applied successfully."
}
# Process command-line arguments
if [ "$#" -eq 0 ]; then
toggle_keyboard_mode
elif [ "$1" = "windows" ]; then
apply_windows_settings
elif [ "$1" = "mac" ]; then
apply_mac_settings
elif [ "$1" = "status" ]; then
if is_windows_mode; then
echo "Currently in Windows mode"
else
echo "Currently in Mac mode"
fi
elif [ "$1" = "help" ]; then
echo "Usage:"
echo " $(basename "$0") - Toggle between Mac and Windows keyboard shortcuts"
echo " $(basename "$0") mac - Switch to Mac keyboard shortcuts"
echo " $(basename "$0") windows - Switch to Windows keyboard shortcuts"
echo " $(basename "$0") status - Show current mode"
echo " $(basename "$0") help - Show this help message"
else
echo "Invalid argument. Use 'mac', 'windows', 'status', or 'help'."
exit 1
fi
# Restart services to apply changes
killall cfprefsd 2>/dev/null || true
/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
@cemlyn007
Copy link
Author

This Gist shows how to apply different versioned com.apple.symbolichotkeys.plist and modify the mouse & trackpad scroll direction. I found this particularly useful when I switch to using Google's Chrome Remote Desktop (RDP) and I don't want keyboard shortcuts triggering Mission Control that take me away from my RDP session when I am for example pressing control+←.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment