IntelliJ IDEA 2021.1 Help

IDE scripting console

The IDE Scripting Console can be used to write simple scripts that automate IntelliJ IDEA features and extract various information. With access to the IntelliJ platform API, you can think of it as a lightweight alternative to a plugin, which adds or modifies some behavior of the IDE.

By default, it supports scripts written in Kotlin, JavaScript, and Groovy. However, you can use any scripting language that is compliant with JSR 223, for example, Python, Ruby, Clojure, and so on.

Some information and examples are available in this gist.

Open the IDE Scripting Console

  1. From the main menu, select Tools | IDE Scripting Console.

  2. Select the desired scripting language.

  3. This opens the IDE Scripting Console tab in the editor, where you can type code and execute it using Ctrl+Enter.

    For example, create a Kotlin script with the following code:

    import com.intellij.openapi.ui.Messages.showInfoMessage var sum: Long = 0L val arr = "35907 77134 453661 175096 23673 29350".split(" ") arr.forEach { sum+=it.length } showInfoMessage((sum.toFloat() / arr.size).toString(), "test")

    Select it all with the mouse pointer or Ctrl+A and then press Ctrl+Enter to run it. You should see the result of executing each line in the Run tool window and a popup dialog titled test with the average length of numbered elements in the array. Click OK to close it.

The scripts are stored in the Configuration directory under consoles/ide. You can also see them in the Project tool window under Scratches and Consoles/IntelliJ IDEA Consoles. If you add a file named .profile followed by the designation of the corresponding language to this directory (for example, .profile.groovy ), it will be executed along with any script that you run. Use the profile to define functions for your scripts.

Last modified: 08 March 2021