Running Commands with IMatch 2017

Started by Mario, April 28, 2017, 02:41:56 PM

Previous topic - Next topic

Mario

IMatch 2017 includes an easy way to run 'commands' from scripts.
I have added a method which allows you to list all commands (e.g. menu  commands, toolbar buttons, keyboard shortcuts) supported by IMatch.

To get this list, send the command v1/imatch/commands/list to IMatch or use the convenient wrapper method commandsList of the IMatch class.


IMatch.commandList().then(function(response) {
    console.log(JSON.stringify(response,null,2));
});


IMatch returns a JSON-formatted list of all commands. For each command, the unique id, the name, the keyboard shortcut and the help text is returned. Most interesting is the unique id. For example, look at this command:

    {
      "id": "ID_CMD_RATING_NONE",
      "text": "Reset &Rating",
      "displayText": "Reset &Rating\t0 ; 0 (zehnertastatur)",
      "hotKey": "0 ; 0 (zehnertastatur)",
      "helpText": "Remove the rating from the current selection (0 ; 0 (zehnertastatur))"
    },


This is the command triggered when you press <0> in the file window or use the "Reset Rating" from the context menu in the file window.

If you want to execute this command from your app, all you need to do is:

IMatch.focusWindow('filewindow.active');
IMatch.commandExecute('ID_CMD_RATING_NONE');


The first line ensures that the input focus is on the active file window (this ensures that Windows directs input to this window).
The second line executes the command.

These two lines reset the rating of all selected files in the active file window.

IMatch.commandExecute('ID_CMD_RATING_1) would set the rating to 1, and IMatch.commandExecute('ID_CMD_RATING_INC) would increment the rating (1 -> 2).

Your app can select the files it wants to manipulate before running the command of course.
Despite that changing metadata in apps is very easy with IMatch 2017, just running a command in one line or code still beats it.

Not all commands can be used that way, but most can.
This may avoid some of the "SendKeys" orgies some users used in BASIC scripts to trigger certain IMatch functionalities.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook