I want a domain com.apple.keyboard.modifiermapping.1452-628-0
to contain the following array:
(
{
HIDKeyboardModifierMappingDst = 2;
HIDKeyboardModifierMappingSrc = 0;
},
{
HIDKeyboardModifierMappingDst = 0;
HIDKeyboardModifierMappingSrc = 2;
},
{
HIDKeyboardModifierMappingDst = 0;
HIDKeyboardModifierMappingSrc = 10;
}
)
I can achieve it by deleting the current value and running three -array-add
commands:
defaults -currentHost delete -g com.apple.keyboard.modifiermapping.1452-628-0
defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-628-0 -array-add '{ HIDKeyboardModifierMappingDst = 2; HIDKeyboardModifierMappingSrc = 0; }'
defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-628-0 -array-add '{ HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 2; }'
defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-628-0 -array-add '{ HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 10; }'
defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-628-0
What syntax can I use to define the array in a single command?
If I run the following script:
defaults -currentHost delete -g com.apple.keyboard.modifiermapping.1452-628-0 defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-628-0 -array '( { HIDKeyboardModifierMappingDst = 2; HIDKeyboardModifierMappingSrc = 0; }, { HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 2; }, { HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 10; } )' defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-628-0
I get an array within an array:
( ( { HIDKeyboardModifierMappingDst = 2; HIDKeyboardModifierMappingSrc = 0; }, { HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 2; }, { HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 10; } ) )
If I try with
-plist
instead of-array
I get anUnexpected argument
.If I run the following script:
defaults -currentHost delete -g com.apple.keyboard.modifiermapping.1452-628-0 defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-628-0 -array ' { HIDKeyboardModifierMappingDst = 2; HIDKeyboardModifierMappingSrc = 0; }, { HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 2; }, { HIDKeyboardModifierMappingDst = 0; HIDKeyboardModifierMappingSrc = 10; }' defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-628-0
I get a syntax error
defaults[22044:679428] Could not parse: ... Try single-quoting it.
Question again: what syntax can I use to define the array in a single command?