More General posts
February 01, 2005
Mac OS X - Opening a Terminal from IntelliJ IDEA

From inside of IntelliJ IDEA I want to be able to right click on a directory or file in the Project view and open a Terminal window already set up with its current directory set to the location of the directory or file. Unfortunately I couldn't find a simple way to do this! There is a command open that will open a file but that by default uses the Finder if you pass it a file or directory and trying open -a Terminal didn't work.

Using applescript its possible to open a Terminal window and issue it commands. If you use

tell application "Terminal"
  activate
  do script with command "cd " & "/Users/foo"
end tell

you end up with a Terminal window open on directory /Users/foo. Now the problem is that the standard way to execute an applescript from the command line, and hence what I have to use from IDEA, doesn't accept parameters. In fact, if you look at the man page for osascript this is listed as one of the bugs. To get around this problem I used osasubr which can execute a subroutine in an applescript and pass it parameters. So, I ended up with an applescript like

on doit(dir)
  tell application "Terminal"
    activate
    do script with command "cd " & quoted form of dir
  end tell
end doit

saved in a file OpenTerminal.scpt and entry for an enternal tool in IDEA with a program of /usr/local/bin/osasubr and parameters of /Users/amoffat/Projects/AppleScript/OpenTerminal.scpt doit $FileDir$

This works but it certainly seems like a lot of work!

Posted by Alex at February 01, 2005 10:31 AM
Comments
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?