» Home

  » Plugins

      » Mime

            » X-App Gestures

Brass Plugins: Mime

 

Cross Application Gestures

There is one extremely shiny feature of Mime that you might not have noticed yet, and it deserves a section all of its own. When we created a custom application and action, one of the Wizard pages was the directive page:

 

As you now know, this is where you tell Mime what to do for each custom action. You make your gesture in an application (like Notepad), Mime sees the custom action attached to the gesture and performs whatever actions you tell it to in the directives section.

There's one directive that is extremely powerful - the "Set Target Window" directive.

 

Set Target Window

So far we've seen how to tell an application to do something when you make a gesture in it. But what about making an entirely separate application do something when you make a gesture?

  • How about making a gesture in Internet Explorer causing WinAmp to load a new MP3?
  • How about a gesture in MS Word causing Trillian to connect to MSN?
  • How about a gesture in Dreamweaver causing Paintshop Pro to load a bitmap?

SetTargetWindow can do all this and more. Cool, huh!

 

The purpose of SetTargetWindow is to say to Mime:

"I don't want to you to send any more directives to the application I made the gesture in. Instead I want you to find
another application and send all these other directives to it instead"

 

When you select "Directive: Set Target Window" this is what you'll see in the directive page of the Custom Action Wizard:

SetTargetWnd takes 2 parameters. The first parameter - class name - is the explicitly matched class name of the top level window to send all subsequent directives to. The second parameter - window title - is the pattern matched string to look for in the titles of all top level windows. Class names and window titles are discussed in detail in the Creating Good Criteria section.

You can supply one or both of these parameters to enhance the window matching process.

Here's a brief example. Let's say we are creating a custom action for Notepad that tells WinAmp to start playing. Follow the steps in the Creating a Custom Application and Action walkthrough until you get to the directive page in the Wizard.

Now we want to tell Mime that this gesture affects WinAmp, not Notepad. The first thing we need to do is to find the class name and window title of WinAmp. We can do this with a window spy tool, the window finder tool or with the Mime secret gesture. Here's the output from the secret gesture:

 

Great, this will be an easy one. Matching on explicit classnames is always better, so we'll use the class name of "Winamp v1.x". We don't need to match on a window title (if we wanted to though, we could pattern match on a window title of "Winamp")

Back to the directives page in the Custom Action Wizard. We add the SetTargetWnd directive, and give it the WinAmp classname like this:

 

Take a close look at this screenshot. We've provided the exact classname for WinAmp and left the window title field blank. When the "Add This Directive" button was clicked, the Custom Action Wizard automatically put a "0" in the window title field to signify it's not needed.

Now every directive after the SetTargetWnd directive will be sent to WinAmp. According to the WinAmp docs the keyboard shortcut to start playing an MP3 is simply to press "x". Let's add that.

Select "Keyboard: Simple Keypress" from the directive type combobox, type "x" in the "Keypresses to send" field and click "Add This Directive". The complete directive string will now look like this:

 

Easy enough! That's all it takes, once you add this custom action you can control WinAmp from gestures in Notepad!

Of course the same principle applies to all other applications. Even if the criteria for your custom application is all blank (in other words, actions for all applications), you can control other applications through the SetTargetWnd directive.

 

RestoreTargetWnd - SetTargetWnd's best friend

The magic doesn't end there though. SetTargetWnd lets you ignore where you made a gesture and change the application to send directives to. But what if you want to do both?

An example works best. Let's say you wanted to make a gesture in Internet Explorer that plays an MP3 in WinAmp, then does a File - Print back in Internet Explorer. This is where RestoreTargetWnd comes in.

RestoreTargetWnd sets the "focus" of Mime back to the application you made the gesture in, for all subsequent directives.

File - Print is "ALT-F" then "p", so the directive line would look like this:

Let's split that down a bit:

SETTARGETWND(Winamp v1.x, 0) Set the window to receive input to WinAmp
   
%% Command delimiter
   
x Send an X to WinAmp - the keyboard shortcut to start playing
   
%% Command delimiter
   
RESTORETARGETWND() Set the window to receive input back to the one the gesture was made in
   
%% Command delimiter
   
[ALT]f[/ALT] Send a ALT-F keypress (open the File menu)
   
%% Command delimiter
   
p Send a P to the original window to access the "Print" menu option
   

 

You can use as many SetTargetWnd and RestoreTargetWnd directives as you want in one directive line. Controlling 5, 10 or 20 apps with one single gesture is easy!