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}

Hi tbone,

I just "re-discovered" this very useful command. And then found that it fails if used in a single display lister, i.e. without a destination tab. To fix that, I added a simple check to line 44:

	if (data.func.desttab)
		text = ReplaceVars(text, /\{\$dst\:.*?\}/gi, data.func.desttab.lister.vars, "$dst:");

Maybe you'd like to do the same in your original code? :smiley:

Anyway, thanks for the command!

With Opus 13, you can also use @output now.

1 Like

Updated to v0.3.8

  • reorder version history

v0.3.7 - 2022-01-19

  • prevent exception if run via DOpus.NewCommand.RunCommand() or CLI tool (..sourcetab.lister not set for some reason)

v0.3.6 - 2017-06-08

  • added logprefix "Say"

v0.3.5 - 2016-01

  • order of variable resolving changed from local to global scope

v0.3.4 - 2015-10

  • data.func.command.deselect = false;
  • bug fix resolving $dst-scoped variables

@MartO
Thanks for reporting! o)
Seems to have been fixed here already including some other smaller enhancements. I now uploaded the latest version, so we are all on the same page!

@leo
Good to know, any tooling to get more output is appreciated! o) I guess "Say" will still be around for some time though, since it works in basically all the places.

Have a nice weekend everybody! o)

3 Likes

Thanks, tbone, for the latest version! The update didn't even take ten years... :laughing:

And thanks, leo, for the pointer. @output is a really neat addition; I hadn't found it yet. Apparently it's a good idea to actually read the detailed release notes for a new version. Who knew? :wink: (Am I hallucinating or did @output appear in the manual just today?)

In case anyone else is interested: It seems to accept variables as well and even works with colors:

@output <#000000 #00FF00>{$glob:myvar}</#>

So it's tough competition for Say ... but I'm not sure yet who will win my heart...

Yes, have a good weekend!

It was in the detailed release notes before, but not in the main part of the manual until today. I noticed it earlier and added it.

1 Like