Open Terminal is a useful TextMate command—it opens a new instance of Terminal.app in the directory of the current file. Terminal.app has improved under Leopard; it now supports tabs. It would be great if the Open Terminal command could open the directory of the current file in a tab of an already opened instance of Terminal.app. (Especially relevant to my use case since I tend to have Terminal.app open anyway with at least one tab dedicated to Wyrd and another dedicated to a bash shell.) So I decided to write an Open Terminal in New Tab command. If you look at the Open Termianl command in the Bundle Editor you will notice that it uses AppleScript to interact with Terminal.app. To open a new tab in Terminal you might expect something like the following to work:
Tell app "Terminal" to make new tab in first window
But, weirdly, “make” fails with Terminal.app. So you need, instead:
Tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
Inelegant. So, a rather hackish command, but if you are interested in opening the directory of the current TextMate document in Terminal.app, you can download it here.
{ 2 } Trackbacks
[…] This is modified version of the script I found at Mark Eli Kalderon’s Blog. […]
[…] should be happy that those made it in. No whining. Allright, one Google search later I found a twisted way of telling Terminal that it should launch a new tab — simulate a keystroke (Cmd-t). Good. One […]
Post a Comment