How to switch Karabiner profile via shortcut?

Solution 1:

Yes, there is, using Karabiner's command-line tool. Paste this into your private.xml:

<vkopenurldef>
    <name>KeyCode::VK_OPEN_URL_SHELL_switchprofile_newitem</name>
    <url type="shell">
        <![CDATA[    /Applications/Karabiner.app/Contents/Library/bin/karabiner select_by_name NewItem    ]]>
    </url>
</vkopenurldef>
<item>
    <name>Switch Profile to NewItem with F4</name>
    <identifier>private.switch1</identifier>
    <autogen>
        __KeyToKey__
        KeyCode::F4,
        KeyCode::VK_OPEN_URL_SHELL_switchprofile_newitem
    </autogen>
</item>

Obviously, you will need to change the name of the profile (here it is NewItem).

If you want to toggle between them with a single hotkey, paste it twice and change the name, then check the box for the profile you want to switch to on each one.

Solution 2:

This definition allows to swtich back and forth between two profiles (in this case profile 0 and 2) by holding the F6 key for longer than 300 milliseconds (before that it defaults to F6). It uses terminal-notifier to deliver notifications as to which profile it has switched to.

<vkopenurldef>
  <name>KeyCode::VK_OPEN_URL_SHELL_toggleprofile_alternative</name>
  <url type="shell">
    <![CDATA[    if test "$(/Applications/Karabiner.app/Contents/Library/bin/karabiner selected)" == "0"; then /Applications/Karabiner.app/Contents/Library/bin/karabiner select 2; /usr/local/bin/terminal-notifier -title "Karabiner" -group "Karabiner" -message "Alternative mode"; else /Applications/Karabiner.app/Contents/Library/bin/karabiner select 0; /usr/local/bin/terminal-notifier -title "Karabiner" -group "Karabiner" -message "Normal mode"; fi    ]]>
  </url>
</vkopenurldef>
<item>
  <name>Toggle Profile "Alternative" with long F6</name>
  <identifier>private.switch1</identifier>
  <autogen>
    __HoldingKeyToKey__ KeyCode::F6, KeyCode::F6, KeyCode::VK_NONE, KeyCode::VK_OPEN_URL_SHELL_toggleprofile_alternative, Option::NOREPEAT, ThresholdMillisecond::RawValue::400
  </autogen>
</item>