Jump to content

Karabiner Elements Profile Switcher


Recommended Posts

The fresh macOS Sierra rewrite of the original Karabiner, the Karabiner Elements qietly supports multiple profiles, which has been one of the core features, historically speaking. Although, as of now, you can define multiple profiles in the ~/.config/karabiner/karabiner.json file, but you can't switch between them easily. This is an important features for people that regularly switch between internal / Apple keyboard and an external USB one, which usually have different layout, hence the need for 2+ profiles.

Karabiner Elements listens for changes in karabiner.json config file, and there is a setting that specifies which profile is currently active – selected: true.

This workflow does the following:

  1. Type keprofile (you can change this if you like), to fetch your profiles defined in karabiner.json and list them in Alfred
  2. Once you select a profile you want to switch to, hit ENTER and the workflow script will edit your karabiner.json file so that the selected profile becomes active

Note that after you switch to a different profile, you can adjust its settings inside Karabiner Elements preferences window, save them and it'll all work seamlessly; the workflow only changes selected: true|false attribute, nothing else.

 

Commands

keprofile - lists your profiles; then ENTER to switch to one

 

 

Download:

http://www.packal.org/workflow/karabiner-elements-profile-switcher

 

Example

Workflow

8LN9mQI.png

 

You can freely edit settings of each profile after switching to it

9rIV5jS.png

Thanks to

@tekezo for creating an awesome key switcher application for OSX / macOS – Karabiner Elements.

@bennypowers for a fresh Karabiner Elements logotype, as submitted in this pull request.

@deanishe for creating an amazing, easy to use Alfred Workflow creation framework – Alfred-Workflow.

Edited by Andy Winecki
formatting
Link to post

Thanks! I tried it now, unfortunately the workflow messes up the karabiner.json file for me (which in my system was at '~/.karabiner.d/configuration/karabiner.json' so I changed this in your workflow scripts), it changes the selected: true|false attributes correctly but the lines in the file are shifted around in a seemingly random manner. My karabiner.json file is similar to the sample file you show at Packal. Any thoughts what may be causing this (macOS 10.12.2, Alfred 3.2.1)?

Edited by cands
Link to post

The script should not touch `~/.karabiner.d/configuration/karabiner.json`. It's written to work only with `~/.config/karabiner/karabiner.json` path, which I believe is the right one in the latest Karabiner Elements.

 

As per shifting lines around – the script parses the JSON file into a python dictionary, then changes it, and then converts the dict into JSON again. So I'd assume the keys in the output JSON would be sorted A-Z. It could be done without changing lines, but I didn't find that important as everything worked out normally for me.

 

I did one change though after publishing the initial workflow, it's not re-uploaded into version 1.1 – I added pretty formatting the output JSON so it's at least readable and editable by hand again.

 

My macOS version: 10.12.2

My Alfred version: 3.2.1

My Karabiner-Elements version: 0.90.76

 

Is your problem just the lines order, or the whole workflow not working at all for you?

Link to post

Thanks for the clarification. I have KE version 0.90.68 so the json file's folder may have changed as you say. The problem for me is the line order, since changing it makes it more difficult to edit the file by hand later. I was afraid that reordering the lines in the script can make it fail, so I didn't even test further. If the file can be kept as is, only changing the true|false setting, it would be better. Anyway, thanks for your work so far.

Link to post
  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...