====== Tool Script ======
{{ :scripting:tool_script1.png?400|Add Tool Script}}Tool script, is a just a script that does not register any events (callbacks) and exists immediately after execution.
If you have written tool script you can call it directly using //Tools->Execute// or you can plug it into UI same way as you do for [[tools:start|external tools]].
If plugging it as an external tool, everything is straight forward:
- In [[tools:manage|Manage Tools]] dialog you create new tool.
- In tool properties select as command path to your tool script.
- Add some icon, give nice title etc
- Add arguments (not really needed, while script can access all variables with scripting, but implemented for convenience)
- Assign shortcut, if you want one
- Catch Output is by default **On** because if you write in [[tools:output|Output]] with tool, it automatically caught by HippoEDIT
- Select where you want to see your tool: in Tools menu, in Context menu, in Tools toolbar
- Done.
The tool script below will write script arguments and selected text from current view into Output pane:
#include "he_utils.js" // from here ax2js comes
#include "he_edit.hejs" // and from here GetSelectedText helper
var arguments = ax2js(ScriptArguments);
Output().write(ScriptName + " is executed with arguments : ");
for (i = 0; i < arguments.length; i++)
Output().write(arguments[i] + " ");
Output().writeln(); // insert line break after last command line parameter
if ( ActiveDocument != null )
{
Output().writeln(ActiveDocument.Path);
Output().writeln(GetSelectedText(ActiveDocument.ActiveView));
}
The output:
C:\temp\tool.js is executed with arguments : C:\temp\tool.js
C:\temp\tool.js
ActiveDocument != null
Which looks in the editor like this:\\
{{:scripting:tool_script2.png|Tool Script and its output}}