Tutorial: Content Matching Rules

Welcome to this tutorial!  This will demonstrate the new content matching functionality available as of Snarl 4.0 Beta 3.

To make this tutorial a bit of fun as well as being practical, it assumes you have a blink(1) USB LED connected to your machine.  Of course, if you don’t have a blink(1) [you should, they’re great fun] you can use some other redirect or display instead.

This tutorial will demonstrate content matching by setting the blink(1) device to orange when Caps Lock is enabled, and turning the blink(1) device off when its disabled.

To get started you will need:

Step 1: Getting set up

Firstly, make sure Snarl is installed and running.  You can open Snarl’s settings by double-clicking on its icon in the system tray, right-clicking the system tray icon and selecting Settings, or by launching a browser and navigating to http://localhost:9989/

Next, copy blink1-tool.exe somewhere easy to get to.  This tutorial is based on it being in my user folder (c:\users\chrisp\) so just replace that path with wherever you’ve put it.

Finally, make sure your blink(1) device is plugged in (if you’re running a VM, make sure it’s connected to the VM.

Step 2: Setting up redirection

The first thing we need to do is create two Run File schemes to turn the blink(1) device on and off.  Navigate to the Run File redirect settings (Redirects > Run File > Settings), you should see the following:

runfile1

Click Add new scheme… and enter the following details:

  • Name: Orange
  • Type: Custom
  • Target: (Path to where you installed blink1-tool.exe)
  • Template: –rgb=255,128,0
  • Run hidden: (Ticked)

The completed scheme should look like this:

runfile2

Click Submit to save the scheme.

Click Add new scheme… again and enter the following details:

  • Name: Off
  • Type: Custom
  • Target: (Path to where you installed blink1-tool.exe)
  • Template: –off
  • Run hidden: (Ticked)

Once again, click Submit to save the scheme.

Let’s now test the two schemes to make sure they work.  Navigate back to the Run File redirect (Redirects > Run File) – you should see the following:

runfile3

Click Test normal priority for the Orange scheme.  The blink(1) should light up orange!  Click Test normal priority for the Off scheme – the blink(1) should turn off.

Step 3: Configuring KeyDaemon

This next step tells KeyDaemon to send notifications when the Caps Lock (and other locks) are enabled and disabled – we need notifications when the state changes for this to work properly.  Navigate to KeyDaemon’s settings (Addons > KeyDaemon > Settings) as follows:

keydaemon1

Tick the Notify when locks are enabled and disabled? checkbox and click Submit.

Step 4: Creating the rules

Now all that’s left is to create the rules which will control the blink(1) device when the Caps Lock key is pressed.  Navigate to the Rules page and click New Rule…

In the Select Rule Source page, pick Caps Lock State Changes from underneath KeyDaemon then, in the Edit Rule page, against where it says Tell Me… click Change and select Orange from underneath the Run File redirect.

Make sure Rule Enabled is ticked and that Always is selected against Presence > Apply When.

Enter “title”, select Contains and enter “on” in the Apply Only When… fields, as below:

rule1

Click Submit to save the rule.

Back on the Rules page click New Rule… once again and select Caps Lock State Changes from KeyDaemon as you did previously.  This time, against Tell Me…, click Change and select Off from underneath the Run File redirect.

Make sure Rule Enabled is ticked and that Always is selected against Presence > Apply When.

Enter “title”, select Contains and enter “off” in the Apply Only When… fields, then click Submit to save the rule.

Back on the Rules page, you should now have the following defined:

rules2

Step 5: Testing Everything

Now we’re ready to test!  Press the Caps Lock key: you should see a notification appear and your blink(1) should turn orange.  Press the Caps Lock key again and the blink(1) should turn off and another notification will appear.

Step 6: Tidying Up

You might not want the notifications appearing now that you’ve got a more visible notification so, for both the rules you created earlier, click Edit and tick the Suppress default rule setting making sure you click Submit to save the changes:

suppress1

Back at the Rules page, you’ll see both rules now have “and suppress the default rule” after them.  Press Caps Lock now and you should still see the blink(1) device turn orange, but no notification will appear.