Difference between revisions of "External script file execution"
m (→Script Error Logging) |
(→Setting the External Script Directories Search Path) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
There is a mechanism to load and execute scripts from ''script directories'' matching a given name scheme (hardcoded: <tt>".*\.groovy"</tt>). | There is a mechanism to load and execute scripts from ''script directories'' matching a given name scheme (hardcoded: <tt>".*\.groovy"</tt>). | ||
+ | |||
+ | Starting with Freeplane 1.2 you do not have to configure the script search path since 'scripts' is the default (see below where that is). | ||
# The list of ''script directories'' is configurable by selecting <tt>tools->Preferences ...</tt> from the menu, and then in the resulting <tt>Preferences</tt> window, click the <tt>Scripting</tt> button. | # The list of ''script directories'' is configurable by selecting <tt>tools->Preferences ...</tt> from the menu, and then in the resulting <tt>Preferences</tt> window, click the <tt>Scripting</tt> button. | ||
Line 11: | Line 13: | ||
<tt>scripts;;C:\temp;;</tt> | <tt>scripts;;C:\temp;;</tt> | ||
− | === Linux | + | === Linux, MacOS X === |
− | |||
− | |||
(todo) | (todo) | ||
− | + | (default: <tt>scripts</tt>, i.e. directory <tt>scripts</tt> in the freeplane user home). | |
− | ( | ||
− | |||
− | |||
− | ( | + | == Adding external libraries == |
+ | If your script needs external libraries (.jar or .class files) add the directory containing them to the "Script classpath", see [[Scripting:_Example_scripts#Scripts_that_need_external_libraries|example scripts]]. | ||
== Executing Scripts == | == Executing Scripts == | ||
Line 28: | Line 26: | ||
== Hot Key Assignment to Execution of Scripts == | == Hot Key Assignment to Execution of Scripts == | ||
*Due to the flexible standard hotkey assignment it's possible to create hotkeys for these scripts. | *Due to the flexible standard hotkey assignment it's possible to create hotkeys for these scripts. | ||
− | For each script there is a submenu with three menu entries: | + | For each script there is a submenu with three menu entries (see [[Scripting#Execution_modes]] for instructions how this can be controlled by the script writer).: |
**''Execute for one selected node'': This will invoke the script for one selected node (arbitrarily choosen), i.e. if three nodes are selected, it will be executed once, with the <tt>node</tt> variable set to one of the selected nodes. Since setting of <tt>node</tt> is not really predictable this variable should not be used. | **''Execute for one selected node'': This will invoke the script for one selected node (arbitrarily choosen), i.e. if three nodes are selected, it will be executed once, with the <tt>node</tt> variable set to one of the selected nodes. Since setting of <tt>node</tt> is not really predictable this variable should not be used. | ||
**''Execute for all selected nodes'': This will invoke the script on every selected node, i.e. if three nodes are selected, it will be executed three times, once for each node with the ''node'' variable set to the respective node. | **''Execute for all selected nodes'': This will invoke the script on every selected node, i.e. if three nodes are selected, it will be executed three times, once for each node with the ''node'' variable set to the respective node. | ||
**''Execute for all selected nodes, recursively'': This will invoke the script on every selected node and recursively on all of its children. | **''Execute for all selected nodes, recursively'': This will invoke the script on every selected node and recursively on all of its children. | ||
***''Note:'' If a node and a child node are both selected, then the script is invoked on the child node twice. | ***''Note:'' If a node and a child node are both selected, then the script is invoked on the child node twice. | ||
− | *To execute a script ''on all nodes'' in a map one has to select the root node and execute the script ''recursively''. | + | *To execute a script ''on all nodes'' in a map one has to select the root node and execute the script ''recursively''. |
== Script Error Logging == | == Script Error Logging == |
Latest revision as of 00:17, 20 March 2014
Contents
Setting the External Script Directories Search Path
There is a mechanism to load and execute scripts from script directories matching a given name scheme (hardcoded: ".*\.groovy").
Starting with Freeplane 1.2 you do not have to configure the script search path since 'scripts' is the default (see below where that is).
- The list of script directories is configurable by selecting tools->Preferences ... from the menu, and then in the resulting Preferences window, click the Scripting button.
- In the Script search path (separate entries by ;;) text box, you can specify additional pathes where Freeplane can search for Groovy Scripts.
Windows
Specify your path as you would normally in windows, just be sure to add a ;; at the end of the path you add to the existing script path.
Example
If you wanted the default %USERPROFILE%\.freeplane\scripts directory, and also wanted to use C:\temp you would set :
scripts;;C:\temp;;
Linux, MacOS X
(todo)
(default: scripts, i.e. directory scripts in the freeplane user home).
Adding external libraries
If your script needs external libraries (.jar or .class files) add the directory containing them to the "Script classpath", see example scripts.
Executing Scripts
- Matching scripts are listed in the menu Extra->Scripts.
Hot Key Assignment to Execution of Scripts
- Due to the flexible standard hotkey assignment it's possible to create hotkeys for these scripts.
For each script there is a submenu with three menu entries (see Scripting#Execution_modes for instructions how this can be controlled by the script writer).:
- Execute for one selected node: This will invoke the script for one selected node (arbitrarily choosen), i.e. if three nodes are selected, it will be executed once, with the node variable set to one of the selected nodes. Since setting of node is not really predictable this variable should not be used.
- Execute for all selected nodes: This will invoke the script on every selected node, i.e. if three nodes are selected, it will be executed three times, once for each node with the node variable set to the respective node.
- Execute for all selected nodes, recursively: This will invoke the script on every selected node and recursively on all of its children.
- Note: If a node and a child node are both selected, then the script is invoked on the child node twice.
- To execute a script on all nodes in a map one has to select the root node and execute the script recursively.
Script Error Logging
- Errors while loading or while execution of scripts are handled by error message popups. (See resources ExecuteScriptError.text and ReadScriptError.text.)