Scripting

From FreeMind
Revision as of 10:56, 23 August 2010 by Dan Polansky (talk | contribs) (remove "FreeMind 0.9.0: The New Features" from prominence; it remains in "See also")
Jump to navigationJump to search

FreeMind 0.9.0 beta series has a scripting facility using Groovy.

Menu

  • Tools > Evaluate: run all the scripts in a mind map
  • Tools > Script Editor

Keyboard

  • Alt + F8: run all the scripts in a mind map

Using

New scripts can be created using the script editor, available from the menu Tools > Script Editor. Alternatively, you can plainly create an attribute whose name starts with "script" such as "script2"; such an attribute is understood by FreeMind to be a script.

To run all the scripts in a mind map, use the menu Tools > Evaluate or press Alt + F8.

To run a single script, use the script editor (Tools > Script Editor), and its menu item Actions > Run. The Run function of the script editor shows the results of the execution in the pane at the bottom, and it shows error messages there, if any.

For more detail, see the FreeMind documentation available from the menu Help > Documentation, the section "New features in version 0.9.0" and the subsection "Scripting support".

Examples

Some example scripts:

  • Set a new text of a node: =12 * 14 (A little trick: scripts starting with "=" replace the text of a node with their results.)
  • Change the text of a node: c.setNodeText(node, node.getText() + " - appended text")
  • Set the text color of a node: c.setNodeColor(node, java.awt.Color.RED)
  • Set the background color of a node: c.setNodeBackgroundColor(node, java.awt.Color.YELLOW)

See also Example scripts.

For another set of examples, see the FreeMind documentation available from the menu Help > Documentation, the section "New features in version 0.9.0" and the subsection "Scripting support".

API

The scripts can access FreeMind's scripting API--application programming interface. Above all, the scripts would typically make use of the methods of MindMapController. The mind map controller is available to scripts as 'c'.

Security

By default, FreeMind scripts are restricted in what they can do on the local computer. The restrictions include those of file operations, network operations and execution of applications. These restrictions can be lifted in user preferences, from the menu Tools > Preferences..., and the section "Scripting".

The available security options for scripting, in the section "Scripting" and subsection "Permissions":

  • Permit File Operations
  • Permit Network Operations
  • Permit to Execute Other Applications
  • Trust Signed Scripts
  • Optional User Key Alias for Signing

Implementation

Scripts are stored in an attribute whose name reads "script" followed with a numeral, meaning in the attribute of the attribute function, not in the attribute of XML.

The script attributes are probably distinguished from non-script attributes by their starting with "script".

An example of storage in XML:

<node TEXT="hello">
<attribute NAME="script1" VALUE="=node.getNodeLevel() + &quot; &quot; + node.getText()"/>
</node>

Limitations

  • Failure unless file operations permitted: Almost all scripts fail unless file operations are permitted for scripting; repeated execution of scripts succeeds, though[1]

See also