Command: Say (print text to the script console)

Say - a simple to use script command to output text to the script console of DO.

Description:

Prints text to the other logs/script console of DO. It's handy while test driving buttons, logging actions and variable values when clicking buttons or printing results after running commands. The command is called say and not echo, print, log, etc. because these are already in use by windows or batch commands. You can also use it to clear the script console before running things that output a lot of text.

Features:

  • colored output (not officially supported, so use at your own risk)
  • resolving of variables of any scope (global/lister/tab..)
  • using standard syntax known from buttons and modifiers:
    • {$<varname>} = {$glob:<varname>}
    • {$lst:<varname>}
    • {$src:<varname>}
    • {$dst:<varname>}

Usage:

To print a regular text:

Say This is regular text!

To print a regular text and show content of a global variable:

Say The global variable "MyVar" is set to: {$myvar}
//or
Say The global variable "MyVar" is set to: {$glob:myvar}

To output a source tab scoped variable:

Say The value of the source tab scoped variable called "TabVar" is: {$src:tabvar}

To print red text:

Say <red>This is red text.

To print white text on red background:

Say <white,red>This is white text on red background.

To clear the script console before printing text:

Say The console has been cleared before.<cls>

Demo:

The codes used to create the output above:

DOpus.Create.Command.RunCommand("Say <white,dpurple>Hello! o) Tthis is a quick colored text output demonstration!<cls>");
DOpus.Create.Command.RunCommand("Say");
PrintCol('blue'); PrintCol('purple'); PrintCol('red'); PrintCol('orange');
PrintCol('yellow'); PrintCol('cyan'); PrintCol('green'); PrintCol('gray');
DOpus.Create.Command.RunCommand("Say");
DOpus.Create.Command.RunCommand("Say <,cyan>This text has some cyan,<clear> <white,red>red<clear>, <white,blue>blue<clear> and <white,black>black bg<clear>, <,cyan>you see? o)");
function PrintCol(col){
	var pad=""; while (pad.length+col.length<10) pad+=" ";
	DOpus.Create.Command.RunCommand("Say <"+col+",black>"+col.toUpperCase() +pad+"<l"+col+"> Light <"+col+
	">Regular <d"+col+">Dark "+ "<white,l"+col+"> LightBG <white,"+col+"> RegularBG <white,d"+col+"> DarkBG ");
}


Hint:

To get the same behaviour as an internal DO command (in regard to resolving codes for each item and being run multiple times), create a usercommand called "ForEach" and use Say in conjunction with ForEach like shown right below the screenshot:


ForEach CMD=Say Processing file: {f}
SetAttr TOGGLEATTR=a

Installation:

To install the command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.
After that the command shall be ready to use in buttons, scripts and externally from dopusrt.exe of course.

cya,
tbone

Download:

Updated to v0.2

  • clears console with
  • supports colored output, watch the screenie! o)

Updated to v0.2a

  • keep text in <...>, if it does not match fg/bg color names

Updated to v0.3.2

  • command-template added to make button variables like {file} work
  • fixed "Say" as the commands name

Added information on how to make "Say" work like a regular internal command, watch the "Hint:" section.
Some more details and the "why" can be found here: Script command vs. internal command and {f}