Open ericbiewener opened 5 months ago
If you'd like to give karabiner.ts
a try, there is a importJson() function for that.
Would that help? From what I can tell karabiner.ts is used to generate JSON. I'd still have to import one rule at a time in Karabiner Elements, no?
karabiner.ts
writes to ~/.config/karabiner/karabiner.json
if using with Node.js or Deno
Karabiner-Elements watches ~/.config/karabiner/karabiner.json and reloads it if updated.
Importing JSON to Karabiner-Elements is only needed when using the Online Editor.
Sorry about the confusion and thanks for pointing it out. I will update the README.
💯 would also like to see this implemented natively.
Though, admittedly, the main reason that I want this feature is because I periodically have to re-add all of my custom complex modifications that I have persisted as JSON files, as Karabiner-Elements clears all of my complex modifications regularly for no apparent reason.
I agree with @noptoboggan , karabiner.json itself has some machine-specific information, so it's not suitable for persistence. I prefer saving just pieces of configuration patches.
I have found the hack to import complex modifications local json with terminal. Add following script to your bashrc.
# Usage: karabiner_import /path/to/keybinding.json
function karabiner_import() {
if [ ! -f "$1" ]; then
echo "[ERROR] File not found: $1"
return 1
fi
open "karabiner://karabiner/assets/complex_modifications/import?url=file://$(realpath "$1")"
}
Then you can import local json files by karabiner_import /path/to/your-local-config.json
:+1:
This triggers the same GUI operation as one of "Add predefined rule".
Thanks to genesy/karabiner-complex-rules-generator: https://github.com/genesy/karabiner-complex-rules-generator/blob/90cbbd1ae1db80bdf06910a2e1da587aada9aab7/src/components/MainForm.tsx#L227-L232
```sh function karabiner_import --description 'Import a Karabiner-Elements complex modification JSON file. Usage: karabiner_import /path/to/config.json' -a json_path if test ! -f $json_path echo "[ERROR] File not found: $json_path" return 1 end open "karabiner://karabiner/assets/complex_modifications/import?url=file://"(realpath $json_path) end ```
I would like to be able to import multiple rules from a JSON file on my machine rather than needing to copy/paste individual rules into the "Add your own rule" text box. Another way to think about this is that the "Add predefined rule" should work with local JSON files, not just imported from the KE-complex_modifications repo.