You can use ImageJ Macro Recorder to recorder to commands for a Groovy script. Simply set macro type to JavaScript, record commands, create script, copy content to Groovy Console and add imports as needed.
Step by step instructions are provided this tutorial.
Use IDE to develop scripts, use Groovy Console to run them in ImageJ. The Groovy Console provides a convenient way for lightweight editing running scripts, including integration with ImageJ. However, an IDE can add many advanced development features. You can create and modify scripts in IDE and use Groovy Console to run them in ImageJ.
The IntelliJ IDEA has great support for working with Groovy (in both Community and Ultimate editions). You can debug scripts and classes, inspect runtime variables. Editor provides syntax highlighting and error marking, code completion, class search, code inspections. You can quickly access API documentation for Groovy, ImageJ, and other libraries in use. And much more.
You may also try Groovy options provided by NetBeans and Eclipse.