v1.2.0.1-beta1
|
The plugin evaluates JavaScript-compatible expressions, from simple math to running (relatively) complex programs.
For the most part this is useful for getting information/data back to Touch Portal, for example to get the result of a math expression as soon as some dynamic value (used in the expression) changes. Such results would be sent to Touch Portal as plug-in "States" (which I will refer to with a capital letter to help avoid confusion with any other kind of state).
That's not an exclusive usage – scripts can also be run that simply do something useful but do not return any result. Or they may run in the background and send Touch Portal State (capital!) updates when new data becomes available (such as watching a file for changes or downloading from a URL). But more on that later.
Expressions/scripts are evaluated by the plugin using an evaluation engine. An engine instance is a complete and isolated environment that can run JavaScript scripts, like a mini Web browser or a continuously-running Node.js application (it's not either of those things, but that's the best analogy I have for now).
An engine instance can persist for the life of the plugin (that is, it exists as long as the plugin keeps running).
The plugin can run multiple engine instances at the same time. (Don't worry, this is not like running a bunch of bloated Firefox browsers... each instance only uses a few KB of memory :-) ).
Other differences between Shared and Private engine instances are described on the next page about the plugin's actions.
Each JavaScript expression initiated from a Touch Portal Action or Connector is referred-to as a Script Instance. The actual actions/connectors are described in following pages, but they all share the same basic principles:
To get any kind of result back from the plugin to Touch Portal the plugin creates Touch Portal States dynamically once you tell it to.
Meaning that to be able to select the new State from Touch Portal's interface you have to first send one of the plugin's actions which creates that State in the first place (with a name of your choice, as you'll see on the next page). It's a bit of a catch-22 and this is sometimes a point of confusion.
So in general the procedure for using any of these results is:
As a "final" detail, note that States in Touch Portal are tracked and uniquely identified by an ID, not the Name displayed in most places. You can see these actual IDs when selecting a State or Value from the +
buttons next to text entry fields and such... they're the part in ${value:...}
macros after the "value:" part and before the closing "}".
When you create a new State/Instance using this plugin's actions (or connectors), the State ID is generated by adding a dsep.
prefix to the Instance Name you specify. This is to help make sure the IDs are unique and not going to overwrite/compete with any other States.
So for example if you run a Script Instance named "My New State Name" and have it create a State, the State's ID will actually be dsep.My New State Name
. When you select that State using those +
buttons, the "macro" Touch Portal inserts would look like ${value:dsep.My New State Name}
OK, enough of that, let's get to the Actions!