Maybe this exists already – I couldn’t find it, so I just wrote it. Of course, I am putting this here as code, but one day I’ll publish a new bundle of TextMate commands which includes this and some of the other ones I’ve put together. I was looking around today for some commands that I might use to augment the Perforce bundle — specifically, I needed a dialog. What I found was some references to the use of CocoaDialog, which is pretty handy. Another use I had envisioned for dialogs in a TextMate command was to be able to run terminal commands *in* the Terminal. After all, sometimes you would like to have something run and dump its output right there in the Terminal, rather than in a new TextMate document or something like that. The Apple Terminal is pretty nice for what it is, and its much better than the Linux KDE terminal, the Windows terminal, and the poor bastard Windows Cygwin terminal. To set up this in TextMate, open the Bundle Editor and create a new Command. Set the command to Save “Nothing”, Input “None”, and Output “Discard”. Give it a key command if you like, and leave the Scope Selector blank. In the Command(s) field, paste the following:
In a nutshell, as the comments indicate, we capture the contents of the field in the dialog that is opened, and stick them into the applescript that we want to run. The applescript part checks to see if there is already a Terminal session window open, and will run the command in the Terminal. If Terminal isn’t open, then it launches it. You (or maybe me in the future) could fancy this up a bit if you wanted by having the Terminal change directory to the directory in which the file you are working on exists. Not sure that is always desirable though for my purposes.
Enjoy it. (if you’re a total geek you probably will, at least in principle)
Additional work needed:
- Escape quotes (you have to do that manually now).
- Have Terminal spawn a new window if it is already running but has no open windows. (need to check for window count in addition to process running)