How to fix private.xml from Karabiner app for Mac OS X to enable Vim-like navigation in the Preview.app?

1

Background information:

I would like to use h, j, k, l navigation in the Preview.app.

A few months ago I found a solution here: https://apple.stackexchange.com/a/188301/127306. Thanks to the Karabiner app and Martijn's Courteaux private.xml file I was able to use hjkl in Preview.

All of the sudden it stopped working. Probably due to either an update of Karabiner or Preview.

Question:

Have you got any idea how to make this .xml file work? Or maybe you know some other workarounds? (I don't want to use shortcuts like command+j however.)


The code below is the private.xml file I use.

<?xml version="1.0"?>
<root>
    <appdef>
        <appname>PREVIEW</appname>
        <equal>com.apple.preview</equal>
    </appdef>

    <item>
        <name>Vi Navigation in Preview</name>
        <identifier>private.preview.vinav</identifier>
        <only>PREVIEW</only>
        <uielementrole_not>AXTextField, AXTextArea</uielementrole_not>
        <modifier_only>
            ModifierFlag::NONE,
            ModifierFlag::SHIFT_L | ModifierFlag::NONE,
            ModifierFlag::SHIFT_R | ModifierFlag::NONE,
        </modifier_only>
        <appendix>Navigate using the HJKL keys</appendix>
        <autogen>__KeyToKey__ KeyCode::J, KeyCode::CURSOR_DOWN</autogen>
        <autogen>__KeyToKey__ KeyCode::K, KeyCode::CURSOR_UP</autogen>
        <autogen>__KeyToKey__ KeyCode::H, KeyCode::CURSOR_LEFT</autogen>
        <autogen>__KeyToKey__ KeyCode::L, KeyCode::CURSOR_RIGHT</autogen>
    </item>
</root>

Notes:

  • The Karabiner version is 10.9.0.
  • I'm using OS X El Capitan however I had this issue on OS X Yosemite as well.

Mateusz Piotrowski

Posted 2015-10-06T21:59:28.700

Reputation: 2 768

Answers

1

tl;dr hotfix

Change this:

<appdef>
    <appname>PREVIEW</appname>
    <equal>com.apple.preview</equal>
</appdef>

to this:

<appdef>
    <appname>PREVIEW</appname>
    <equal>com.apple.Preview</equal>
</appdef>

Note: if it doesn't solve your problem then look at the Update below.

What was the case?

It turns out the issue was that the identifier of the Preview app should be com.apple.Preview and not com.apple.preview.

I don't know however why com.apple.preview stopped to be a legal identifier of the Preview app. Either Karabiner became case sensitive or Apple decided to change the identifier (which is unlikely).

One way or another, the solution is quite easy.

If you have some troubles with Karabiner you can try to troubleshoot the problem using Karabiner's EventView and reading the manuals: general manual, private xml manual.

Update

This feature has stopped working once again a while ago.

The solution is to remove the <appdef> part completely. Restart both the Preview App and Karabiner after a successful removal.

My private.xml looks like this at the moment:

<?xml version="1.0"?>
<root>
    <!-- <appdef> -->
        <!-- <appname>PREVIEW</appname> -->
        <!-- <equal>com.apple.Preview</equal> -->
    <!-- </appdef> -->
    <item>
        <name>Vi Navigation in Preview</name>
        <identifier>private.preview.vinav</identifier>
        <only>PREVIEW</only>

        <appendix>Navigate using the HJKL keys</appendix>
        <autogen>__KeyToKey__ KeyCode::J, KeyCode::CURSOR_DOWN</autogen>
        <autogen>__KeyToKey__ KeyCode::K, KeyCode::CURSOR_UP</autogen>
        <autogen>__KeyToKey__ KeyCode::H, KeyCode::CURSOR_LEFT</autogen>
        <autogen>__KeyToKey__ KeyCode::L, KeyCode::CURSOR_RIGHT</autogen>
    </item>
</root>

Mateusz Piotrowski

Posted 2015-10-06T21:59:28.700

Reputation: 2 768