Simple textmate applescripting question ([TxMt] TermMate bug)
paul.mccann at adelaide.edu.au
Wed Nov 1 01:07:25 UTC 2006
> OK, I think this should work for iTerm. It opens a new tab and
> goes to the directory corresponding to the file displayed in the
> frontmost TextMate window:
Thanks for the script: I experimented with this a bit, and it seems
to trip over (yawn inducing, I know...) spaces in either the
directory path or the filename. So it's probably a matter or
inserting some ugly quotes into the commands, as per my modified
version below. It'd also be nice to cover the case when it's
mistakenly called it without a file open, so I've thrown in a minimal
try loop to cover that. Finally, a "clear" command gets rid of the
ugly dirname command in the new terminal window. Those who don't have
the working dir as part of their prompt might want to keep that in
there to give a clue as to where they've been dropped. Anyway, for
what it's worth (and sorry for making your clean script ugly!),
here's my version.
[I'm saving this as an app in Script Editor and calling it from QS.
Wow, applescript's a *lot* faster than the last time I looked at it.
I guess having a shiny new machine also helps!]
tell application "TextMate"
set ThePath to path of the first document
display dialog "No file open?"
set ArgString to "$( dirname " & "\"" & ThePath & "\"" & ")"
tell application "iTerm"
make new terminal
tell the first terminal
activate current session
launch session "Default Session"
tell the last session
write text "cd " & "\"" & ArgString & "\""
write text "clear"
More information about the textmate