Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Most of the time, I like the "caps lock" to be mapped to the control key. Sometimes, I want it to be bound to "caps lock". I want to switch it in a shell script, so I can do it automatically or via a keyboard shortcut.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The settings are stored in ~/Library/Preferences/ByHost/.GlobalPreferences*.plist, but I don't know any way to apply changes to it without logging out and back in. KeyRemap4MacBook has a command line utility that allows disabling and enabling settings, but it doesn't work with PCKeyboardHack.

This only changes the settings for one keyboard and doesn't work if the system language is not English.

tell application "System Preferences"
    reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell window 1 of process "System Preferences"
    click button 1 of tab group 1
    tell sheet 1
        tell pop up button 4
            click
            delay 0.1
            if value is "⇪ Caps Lock" then
                click menu item 2 of menu 1
            else
                click menu item 1 of menu 1
            end if
        end tell
        click button "OK"
    end tell
end tell
quit application "System Preferences"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.