Created
October 4, 2014 05:25
-
-
Save mitchty/443202776055fd485927 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
vars: | |
- kb_key: "com.apple.keyboard.modifiermapping" | |
- kb_map_dest: "HIDKeyboardModifierMappingDst" | |
- kb_map_src: "HIDKeyboardModifierMappingSrc" | |
tasks: | |
- shell: > | |
ioreg -p IOUSB -c IOUSBDevice | | |
grep -e class -e idVendor -e idProduct | | |
grep -A2 Internal | grep idVendor | awk -F'= ' '{print $2}' | |
register: id_vendor | |
- shell: > | |
ioreg -p IOUSB -c IOUSBDevice | | |
grep -e class -e idVendor -e idProduct | | |
grep -A2 Internal | grep idProduct | awk -F'= ' '{print $2}' | |
register: id_product | |
- name: "Read builtin keyboard map for caps lock setup" | |
shell: > | |
defaults -currentHost read -g | |
{{ kb_key }}.{{ id_vendor.stdout }}-{{ id_product.stdout }}-0 | |
register: current_layout | |
- name: "Ensure builtin keyboard maps caps lock to control" | |
shell: > | |
defaults -currentHost write -g | |
{{ kb_key }}.{{ id_vendor.stdout }}-{{ id_product.stdout }}-0 | |
-array '({{{ kb_map_dest }}=2;{{ kb_map_src }}=0;})' | |
when: current_layout.stdout != > | |
'( | |
( | |
{ | |
HIDKeyboardModifierMappingDst = 2; | |
HIDKeyboardModifierMappingSrc = 0; | |
} | |
) | |
)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The failure I get when running:
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [shell ioreg -p IOUSB -c IOUSBDevice | grep -e class -e idVendor -e idProduct | grep -A2 Internal | grep idVendor | awk -F'= ' '{print $2}'
] ***
changed: [localhost]
TASK: [shell ioreg -p IOUSB -c IOUSBDevice | grep -e class -e idVendor -e idProduct | grep -A2 Internal | grep idProduct | awk -F'= ' '{print $2}'
] ***
changed: [localhost]
TASK: [Read builtin keyboard map for caps lock setup] *************************
changed: [localhost]
TASK: [Ensure builtin keyboard maps caps lock to control] *********************
fatal: [localhost] => error while evaluating conditional: current_layout.stdout != > '( ( { HIDKeyboardModifierMappingDst = 2; HIDKeyboardModifierMappingSrc = 0; } ) )'
FATAL: all hosts have already failed -- aborting