Skip to content

Instantly share code, notes, and snippets.

@mitchty
Created October 4, 2014 05:25
Show Gist options
  • Save mitchty/443202776055fd485927 to your computer and use it in GitHub Desktop.
Save mitchty/443202776055fd485927 to your computer and use it in GitHub Desktop.
---
- 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;
}
)
)'
@mitchty
Copy link
Author

mitchty commented Oct 4, 2014

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

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