Scripted Control of IDEA

Hi,

I would like to control some aspects of IDEA's operation from a script (either a stock shell script or AppleScript, since I'm on Mac OS X). My requirements are pretty simple: Launch the app, if necessary. Open a project and open some source files within that project.

So far, I've found that the I can launch the app (using the OS X built-in "open" command), open a project (by directly invoking the app launcher with the parent directory of the project's .idea subdirectory as an argument).

I can also open source files in the same way, by invoking the IDEA launcher once for each file I wish to open. Owing to its size, the time it takes to invoke the IDEA launcher is considerable, so opening more than a handful of files can take a long time.

There is also the OpenInIDEA plug-in which can open source files (but not projects). It is somewhat faster than using the IDEA launcher to open files.

While the IDEA launcher will open files in the front-most project window, OpenInIDEA will present a pop-up requesting the user to select the project to use (if more than one is open). Both of these will allow on only one file per invocation.

Additionally, timing can be an issue. If the app is not running, then the time required to launch it must be taken into account. Merely waiting until the appropriate process(es) are running is inadequate, since much initialization processing is performed by IDEA when it first starts up. A similar issue arises between opening a project and opening files within it.

All in all, trying to achieve even rudimentary scripting control over IDEA using these mechanism is problematic.


Is there a better way??


Randall Schulz

4 comments
Comment actions Permalink

Use the Tools | Create Command Line Launcher action. It creates a Python script that will open files in the specific IntelliJ IDEA instance from which you've invoked the action. You can either use the script as-is, or look at what it does and modify as needed.

It will still take a while to open the project for the first time, but opening specific files after that is quite fast and does not open any popups.

0
Comment actions Permalink

Thank you, Dmitry. This seems to do what I need.

The only question I still have is whether there's any positive way to synchronize with: 1) Application launch / readiness to accept project open commands; 2) Project open / readiness to accept file open commands.

As it stands, I still have sleep calls in my code, which as you can imagine is much less than ideal.


Randy

0
Comment actions Permalink

I don't think we have any good solution for this.

0
Comment actions Permalink

Dmitry,

OK. I can live with this, but perhaps a simple scriptable status request that reports IDEA's current status would be doable. E.g.:

  1. Not running
  2. Starting up
  3. Up, running and ready to accept requests but with no project currently open
  4. Up & running with a project open (and which project is front-most)


One would still have to poll, but at least not blindly.


Randall Schulz

0

Please sign in to leave a comment.