Set environment variables

Karabiner-Elements references several environment variables internally. Additionally, the shell_command and open_application used in Complex Modifications are also affected by environment variables. To support this, we provide a way to define them.

Karabiner-Elements loads environment variables from /Library/Application Support/org.pqrs/config/karabiner_environment if the file exists. If you define PATH and others there, shell commands and opened apps via shell_command and open_application inherit these environment variables.

Example

You need to run your editor with root privileges to edit the karabiner_environment file. For example, you can edit it by running the following commands in Terminal.

sudo nano '/Library/Application Support/org.pqrs/config/karabiner_environment'

Here is an example of the karabiner_environment file.

# Add ~/opt/bin to PATH
PATH=$HOME/opt/bin:$PATH
# Set locale
LC_ALL=C

After modifying the karabiner_environment file, you need to restart the karabiner_console_user_server process to apply the changes. You can do it by running the following commands in Terminal.

launchctl kickstart -k gui/$(id -u)/org.pqrs.service.agent.karabiner_console_user_server

Change where karabiner.json is saved

You can also use this mechanism to change where Karabiner-Elements stores its files. The two environment variables used for this are:

  • XDG_CONFIG_HOME
  • XDG_DATA_HOME

For example, the following configuration changes the karabiner.json location under ~/Library/Application Support.

XDG_CONFIG_HOME=$HOME/Library/Application Support/org.pqrs/config
XDG_DATA_HOME=$HOME/Library/Application Support/org.pqrs/data

Note: karabiner.json is stored at $XDG_CONFIG_HOME/karabiner/karabiner.json.