- Installation and configuration
- Script example
- Verification in Freeplane
- Bonus - non-Freeplane Groovy script
Here's a procedure for setting up IntelliJ IDEA.
See IDE setup for an alternative, using Gradle.
Installation and configuration
- Go to https://www.jetbrains.com/idea/download/
- Choose Community (direct download link for Windows: https://www.jetbrains.com/idea/download/download-thanks.html?platform=windows&code=IIC)
- Install IntelliJ IDEA (
Next
,Next
,Next
; the default options are fine) - Launch IntelliJ IDEA
- On the Welcome screen, choose
New Project
Name:
freeplane-scriptingLanguage:
GroovyBuild system:
IntelliJJDK:
if none detected, selectDownload JDK
and choose version 17. AnyVendor:
will do, e.g. Eclipse Temurin ...Groovy JDK
: chooseSpecify Groovy SDK home
and navigate to your Freeplane installation directory then toplugins
and selectorg.freeplane.plugin.script
; confirm withOK
(e.g.C:\Program Files\Freeplane\plugins\org.freeplane.plugin.script
- you can copy-paste)- Click
Create
- Once created, go to
File->Project structure (Ctrl+Alt+Shift+S)
- Then to
Libraries
, and in the middle pane (abovegroovy-#.#.#
) click+
>Java
- Navigate to your Freeplane installation directory and select
freeplanelauncher.jar
(e.g.C:\Program Files\Freeplane\freeplanelauncher.jar
- you can copy-paste) - Confirm with
OK
the message "Library 'freeplanelauncher' will be added to the selected modules." - In the far-right pane click
+
(abovefreeplanelauncher.jar
) - Navigate to your Freeplane installation directory >
core
>org.freeplane.core
, selectlib
and confirm withOK
(e.g.C:\Program Files\Freeplane\core\org.freeplane.core\lib
- you can copy-paste) - And again
+
> Freeplane installation >plugins
>org.freeplane.plugin.script
, selectlib
and confirm withOK
(e.g.C:\Program Files\Freeplane\plugins\org.freeplane.plugin.script\lib
) - Close the Project Structure window with
OK
at the bottom
The installation is done. You are ready to start creating your first script.
Script example
In IntelliJ IDEA, right-click on the (blue) folder src > New->Groovy Script
and in the dialog write the name hello.
- In the file (right-hand pane), start writing
def c = ScriptUtils
. A drop-down will appear - Choose the (first) entry pointing to
org.freeplane.plugin.script.proxy
. It will add a line at the topimport org.freeplane.plugin.script.proxy.ScriptUtils
- Continue writing in line 3. Put a dot after
ScriptUtils
and wait for a drop-down to appear. Selectc()
(withDown
) and confirm withEnter
Enter
to the next line, then writedef node = ScriptUtils.n
and wait for a drop-dwonto appear withnode()
as the first item - confirm it withEnter
- In a new line type
c.stat
and selectstatusInfo
. You can useDown
Enter
or your mouse - Then type
= "Hello. Current node id: ${node.id}
- Finally, copy the path to your src folder, by selecting it (in the left-hand pane) and pressing
Ctrl+Shift+C
Verification in Freeplane
- In Freeplane, open
Tools->Preferences… (Ctrl+Comma)
and go toPreferences…->Plugins->Scripting->Script search path (see tooltip)
- Paste your path to src (something like
C:\Users\<User>\IdeaProjects\freeplane-scritping\src
) and confirm withOK
- Restart Freeplane
- Go to
Tools->Script->Hello
to run it - Verify in the status bar that you can see
Hello. Current node id: ID_#######
Bonus - non-Freeplane Groovy script
In Intellij IDEA, you can also write and execute regular Groovy scripts, not only scripts meant for Freeplane. Here's an example.
- Right-click on your (blue) src >
New->Groovy Script
and give it a name, e.g.currentWeather
- Copy and paste the code
import groovy.json.JsonSlurper
// set your location
float latitude = 50.0
float longitude = 20.0
// get the text from the web
def link = "https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true"
// print it so that you can click on the link to be opened in your web browser
println(link)
// query OpenMeteo for the current weather information
def urlCurrentWeatherInLocation = new URL(link)
def textReturnedFromOpenMeteo = urlCurrentWeatherInLocation.text
// uncomment the next line (and add an import for JsonOutput) to print the returned text
//println(JsonOutput.prettyPrint(textReturnedFromOpenMeteo))
// convert text to a HashMap
def mapFromJson = new JsonSlurper().parseText(textReturnedFromOpenMeteo)
// print the interesting bits
println('-' * 45)
println(" Current temperature (at ${mapFromJson['latitude']} ${mapFromJson['longitude']}): ${mapFromJson['current_weather']['temperature']}")
println('-' * 45)
- Run it with
Ctrl+Shift+F10