Legacy script support - jobisoft/quicktext GitHub Wiki

Script support has changed significantly with Quicktext v6. The methods described on this page are deprecated and no longer supported with the release of Quicktext v6.

Quicktext scripts are created in the Quicktext settings window in the scripts tab.

Once you have created a script with the name "TestScript" you can call it in one of your templates:

[SCRIPT=TestScript](/jobisoft/quicktext/wiki/SCRIPT=TestScript)

Quicktext scripts are written using the Javascript language, and what ever you return is going to be inserted instead of the SCRIPT tag. A simple script would be something like:

var date = new Date();
if (date.getHours() < 12)
  return "Good morning";
else
  return "Good afternoon";

Passing variables

If you want to use variables, you can call your script with:

[SCRIPT=TestScript](/jobisoft/quicktext/wiki/myvar) 

To get the myvar-value in the script, access the mVariables array:

var variable = this.mVariables[0];
return variable;

You can use as many variables as you want. To go through all variables you can do this:

var vars = [];
for (var i = 0; i < this.mVariables.length; i++)
  vars.push(this.mVariables[i]);
return vars.length;

Example script using variables

Since you can use tags recursively, the above example script can be extended to:

var date = new Date();
if (date.getHours() < 12)
  return "Good morning " + this.mVariables[0];
else
  return "Good afternoon " + this.mVariables[0];

Call it in your script like so:

[SCRIPT=TestScript](/jobisoft/quicktext/wiki/[[TO=firstname)]]

Advanced usage

You can also access all the values that you would get by using the tags. There are two types of functions that you can use:

await this.mQuicktext.get_{tagname}(); 

and

await this.mQuicktext.process_{tagname}(); 

with the tagname in lowercase. The get-function is what Quicktext uses to process the tags so the function needs the same variables as the tag does. It takes an array of variables, so for a tag like [TO=firstname](/jobisoft/quicktext/wiki/TO=firstname) you would get the same value in a script by calling:

let firstname = await this.mQuicktext.get_to(["firstname"]);

The process-function will provide access to the entire dataset. You can dump it into an alert box by calling:

this.mWindow.alert(JSON.stringify(await this.mQuicktext.process_to()));

Most process-functions don't need any variables but some do. You will have to try (we do not know).

Executing scripts

It is also possible to execute another script by calling:

var output = await this.mQuicktext.get_script(["GetEnvironmentVariable", "COMPUTERNAME"])

GetEnvironmentVariable is the scriptname, COMPUTERNAME is the first parameter

Locate Thunderbird functions

Search the Thunderbird code for related functions to call in your scripts: https://searchfox.org/comm-central/source