I have looked at the sample code for Karabiner where you can create a filter that applies to a window name, but I would like to apply the filter, when I am creating new emails. Since the window name changes, I would like to filter on the Application Bundle Identifier instead. Does someone have an XML example of filtering on Application Bundle Identifier?
The developer's manual† provides both steps to determine the app bundle identifier as well as examples of usage. I have included one of my own below.
You must first determine if the app you're interested in is pre-defined by Karabiner. Check appdef.xml and search that page for your app's identifier.
If it wasn't found in the existing definitions, you will need to define a name for the application that you will use in <item>
blocks later. (Neither of these are great examples, as they are both pre-defined in appdef.xml for use under WORD
and GOOGLE_CHROME
, respectively.)
<?xml version="1.0"?>
<root>
<appdef>
<appname>MWORD</appname>
<equal>com.microsoft.Word</equal>
</appdef>
<appdef>
<appname>CHROME</appname>
<equal>com.google.Chrome</equal>
</appdef>
Instead of using <equal>
, which as the name implies only matches exact strings (including case), you can use <prefix>
or <suffix>
to match against the beginning or end of the app bundle identification string, respectively.
Once you've done this, when you're creating your item, you have a few options on filtering. First is to restrict to just that particular application, which I believe is your goal.
<item>
<identifier>private.fixscrollwheel</identifier>
<name>Always Rotate Scroll Wheel</name>
<only>CHROME</only>
<autogen>
__FlipScrollWheel__
Option::FLIPSCROLLWHEEL_ROTATE,
</autogen>
</item>
Note the <only>
tag. This restricts the above item to only working with an app whose bundle identifier is com.google.Chrome
, since that's what CHROME
corresponds to in the <appdef>
tag at the top.
You can define multiple applications to be matched by simply including more appname
s in your <only>
tag, such as this:
<only>CHROME, MWORD, MAIL</only>
You can also do the inverse, i.e. all applications except those listed, by changing <only>
to <not>
.
† The original developer manual link is now dead as Karabiner is no longer actively maintained. This answer applied to Karabiner, not Karabiner Elements, and may or may not work with the latter.