Scripting

From FreeMind
Jump to navigationJump to search

Since Release 0.9.0, FreeMind has a scripting facility using Groovy programming language. The best way to get started is perhaps by reading Scripting/Mind map documentation, the wiki version of the mind map documentation originally written by Christian Foltin. What follows here is less informative and consolidated than the mind map documentation. Another source is the dedicated page Example scripts for scripts supplied by FreeMind users.

Using

Each script is stored in a named attribute of a node, named for example as "script1" or "script2". One node can have several scripts attached. There is no way to store scripts in a script file for the whole application; scripts can only be stored in mind maps[verify].

To add a new script to a node:

  • Use the script editor, available from the menu Tools > Script Editor. A window pops up. There, choose menu Action > New script. A new script name appears in the top left pane. Enter the script into the top right pane. Then you can choose menu Actions > Save and Exit.
  • Alternatively, you can create an attribute whose name starts with "script" such as "script2"; such an attribute is understood by FreeMind to be a script.

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.

To run all the scripts in a mind map:

  • Use the menu Tools > Evaluate or press Alt + F8. By default, the function asks for confirmation, for security reasons.

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".

Access points

Access points to scripting functionality, for reference:

  • Menu: Tools > Script Editor
  • In Script Editor
    • Menu: Actions > New Script
    • Menu: Actions > Run
    • Menu: Actions > Sign Script...
    • Menu: Dismiss Changes and Exit
    • Menu: Save and Exit
  • Menu: Tools > Evaluate: run all the scripts in a mind map; kyboard shortcut: Alt + F8

Examples

Some example scripts:

  • Setting a new text of a node: =12 * 14 (A little trick: scripts starting with "=" replace the text of a node with their results.)
  • Changing the text of a node: c.setNodeText(node, node.getText() + " - appended text")
  • Setting the text color of a node: c.setNodeColor(node, java.awt.Color.RED)
  • Setting 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".

Script editor

FreeMind has a very simplistic script editor, available from menu Tools > Script Editor. The editor has no color highlighting of code, and no specific support for writing Groovy scripts: it is basically a plain text editor like Notepad.

The editor has three panes: left one, right one, and bottom one. The left pane shows a list of scripts attached to a node. The right pane shows the script selected in the left pane. The bottom pane shows the results of the execution of a script.

The actions available in the menu Action of the script editor are New Script, Run, Sign Script, Dismiss Changes and Exit, and Save and Exit.

The action Action > New Script adds a new script to the left pane, named as "script1", "script2", etc. The newly created script can be edited in the right pane once the name of the script is selected in the left pane.

The action Action > Run runs the script selected in the left pane, and shows the result of running the script in the bottom pane, including any error messages.

The action Action > Sign Script makes it possible to sign a script. [To be documented].

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'.

These are the variables made available to scripts and their types:

def MindMapController c // the controller

def MindMapNode node // the node the script is run on

def HashMap cookies sScriptCookies // A hashmap of key-value pairs (WHAT IS THIS ANYWAY?)

It is suggested the programmer uses the Freemind sourced code and an IDE to explore the types and what methods are available.

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

Groovy

The scripting engine and language of FreeMind is Groovy. To find out about Groovy, you can check the following web resources:

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>

Scripting is implemented as an external plugin.

Package: freemind/plugins/script/

Limitations

  • There is no way to store scripts in a script file for the whole application; scripts can only be stored in mind maps[verify].

See also