Hi:
I am trying to write a simple osascript command-line utility that acquires the directory of the file displayed in the frontmost TextMate editor window, and am having trouble.
I've been trying to use applescript syntax such as this:
osascript<< END tell application "TextMate" activate do shell script "echo $TM_DIRECTORY" end tell END
but the variable $TM_DIRECTORY is apparently empty.
Is there another way to accomplish this, with or without applescripting? (I'd prefer a less pathological scripting language.)
Thanks.
Bill
On 13/8/2006, at 5:02, William Scott wrote:
I am trying to write a simple osascript command-line utility that acquires the directory of the file displayed in the frontmost TextMate editor window, and am having trouble.
[...] but the variable $TM_DIRECTORY is apparently empty.
Is there another way to accomplish this, with or without applescripting? (I'd prefer a less pathological scripting language.)
The shell variables are only available from inside TextMate.
You are not running this as a normal TextMate command?
On Mon, 14 Aug 2006, Allan Odgaard wrote:
On 13/8/2006, at 5:02, William Scott wrote:
I am trying to write a simple osascript command-line utility that acquires the directory of the file displayed in the frontmost TextMate editor window, and am having trouble.
[...] but the variable $TM_DIRECTORY is apparently empty.
Is there another way to accomplish this, with or without applescripting? (I'd prefer a less pathological scripting language.)
The shell variables are only available from inside TextMate.
You are not running this as a normal TextMate command?
That's right. I want to embed this in a shell script as an osascript.
Basically, if I could come up with something viable in Applescript like
"set ThePath to the POSIX path of the frontmost Textmate window"
I would be happy.
By analogy, this works for the Finder:
http://xanana.ucsc.edu/Library/init/zsh/local-functions/darwin/posd
It returns the $PWD of the directory in the frontmost Finder window.
Hi Bill:
I was hoping for something similar when I wrote to the mailing list a couple of months ago. If $TM_DIRECTORY could be made available to the outside world via applescript, morons like me could make use of this.
If he does let you hack on it, I'd be grateful for this functionality too.
Thanks.
Bill
PS: What I have in mind is something similar to Gary Kerbaugh's Terimal/iTerm -- Finder interaction osa/shell scripts: http:// xanana.ucsc.edu/xtal/terminal_finder_interactions.html
William G. Scott
contact info: http://chemistry.ucsc.edu/~wgscott
Begin forwarded message:
From: William Scott wgscott@chemistry.ucsc.edu Date: August 12, 2006 8:02:30 PM PDT To: textmate@lists.macromates.com Subject: Simple textmate applescripting question Reply-To: wgscott@chemistry.ucsc.edu
Hi:
I am trying to write a simple osascript command-line utility that acquires the directory of the file displayed in the frontmost TextMate editor window, and am having trouble.
I've been trying to use applescript syntax such as this:
osascript<< END tell application "TextMate" activate do shell script "echo $TM_DIRECTORY" end tell END
but the variable $TM_DIRECTORY is apparently empty.
Is there another way to accomplish this, with or without applescripting? (I'd prefer a less pathological scripting language.)
Thanks.
Bill
To get the full path of the first document, you can run:
osascript -e 'tell app "TextMate" to return path of first document'
I reckon it is easier to call dirname on that, than to try and make AppleScript split it up. E.g.:
dirname "$(osascript -e 'tell app "TextMate" to return path of first document')"
On 31. Oct 2006, at 19:45, William Scott wrote:
Hi Bill:
I was hoping for something similar when I wrote to the mailing list a couple of months ago. If $TM_DIRECTORY could be made available to the outside world via applescript, morons like me could make use of this.
If he does let you hack on it, I'd be grateful for this functionality too.
Thanks.
Bill
PS: What I have in mind is something similar to Gary Kerbaugh's Terimal/iTerm -- Finder interaction osa/shell scripts: http:// xanana.ucsc.edu/xtal/terminal_finder_interactions.html
William G. Scott
contact info: http://chemistry.ucsc.edu/~wgscott
Begin forwarded message:
From: William Scott wgscott@chemistry.ucsc.edu Date: August 12, 2006 8:02:30 PM PDT To: textmate@lists.macromates.com Subject: Simple textmate applescripting question Reply-To: wgscott@chemistry.ucsc.edu
Hi:
I am trying to write a simple osascript command-line utility that acquires the directory of the file displayed in the frontmost TextMate editor window, and am having trouble.
I've been trying to use applescript syntax such as this:
osascript<< END tell application "TextMate" activate do shell script "echo $TM_DIRECTORY" end tell END
but the variable $TM_DIRECTORY is apparently empty.
Is there another way to accomplish this, with or without applescripting? (I'd prefer a less pathological scripting language.)
Thanks.
Bill
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Oh great, thanks.
Here is a shell script (or zsh function) to change the directory (and/or optionally the Finder window) to the directory corresponding to the frontmost TextMate document.
http://xanana.ucsc.edu/Library/init/zsh/local-functions/darwin/cdt
I'll do the inverse when I get my kid to go back to sleep.
Bill
On Tue, 31 Oct 2006, Allan Odgaard wrote:
To get the full path of the first document, you can run:
osascript -e 'tell app "TextMate" to return path of first document'
I reckon it is easier to call dirname on that, than to try and make AppleScript split it up. E.g.:
dirname "$(osascript -e 'tell app "TextMate" to return path of first document')"
On 31. Oct 2006, at 19:45, William Scott wrote:
Hi Bill:
I was hoping for something similar when I wrote to the mailing list a couple of months ago. If $TM_DIRECTORY could be made available to the outside world via applescript, morons like me could make use of this.
If he does let you hack on it, I'd be grateful for this functionality too.
Thanks.
Bill
PS: What I have in mind is something similar to Gary Kerbaugh's Terimal/iTerm -- Finder interaction osa/shell scripts: http:// xanana.ucsc.edu/xtal/terminal_finder_interactions.html
William G. Scott
contact info: http://chemistry.ucsc.edu/~wgscott
Begin forwarded message:
From: William Scott wgscott@chemistry.ucsc.edu Date: August 12, 2006 8:02:30 PM PDT To: textmate@lists.macromates.com Subject: Simple textmate applescripting question Reply-To: wgscott@chemistry.ucsc.edu
Hi:
I am trying to write a simple osascript command-line utility that acquires the directory of the file displayed in the frontmost TextMate editor window, and am having trouble.
I've been trying to use applescript syntax such as this:
osascript<< END tell application "TextMate" activate do shell script "echo $TM_DIRECTORY" end tell END
but the variable $TM_DIRECTORY is apparently empty.
Is there another way to accomplish this, with or without applescripting? (I'd prefer a less pathological scripting language.)
Thanks.
Bill
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
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:
tell application "TextMate" set ThePath to path of the first document end tell
set ArgString to "cd $( 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 ArgString end tell end tell end tell
On Oct 31, 2006, at 10:45 AM, William Scott wrote:
Hi Bill:
I was hoping for something similar when I wrote to the mailing list a couple of months ago. If $TM_DIRECTORY could be made available to the outside world via applescript, morons like me could make use of this.
If he does let you hack on it, I'd be grateful for this functionality too.
Thanks.
Bill
PS: What I have in mind is something similar to Gary Kerbaugh's Terimal/iTerm -- Finder interaction osa/shell scripts: http:// xanana.ucsc.edu/xtal/terminal_finder_interactions.html
William G. Scott
contact info: http://chemistry.ucsc.edu/~wgscott
Begin forwarded message:
From: William Scott wgscott@chemistry.ucsc.edu Date: August 12, 2006 8:02:30 PM PDT To: textmate@lists.macromates.com Subject: Simple textmate applescripting question Reply-To: wgscott@chemistry.ucsc.edu
Hi:
I am trying to write a simple osascript command-line utility that acquires the directory of the file displayed in the frontmost TextMate editor window, and am having trouble.
I've been trying to use applescript syntax such as this:
osascript<< END tell application "TextMate" activate do shell script "echo $TM_DIRECTORY" end tell END
but the variable $TM_DIRECTORY is apparently empty.
Is there another way to accomplish this, with or without applescripting? (I'd prefer a less pathological scripting language.)
Thanks.
Bill
On 1. Nov 2006, at 01:14, William Scott wrote:
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: [...]
Just FYI in TextMate, if you press ⌃⇧O, it will open a Terminal window with the current working directory to that of the current file in TM.
We could improve that to check if iTerm is running, and have it use iTerm instead, if that is the case.
Bill wrote...
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!]
Cheers, Paul
======================================================================== tell application "TextMate" try set ThePath to path of the first document on error display dialog "No file open?" return end try end tell
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" end tell end tell end tell
On 11/1/06, William Scott wgscott@chemistry.ucsc.edu wrote:
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:
tell application "TextMate" set ThePath to path of the first document end tell
set ArgString to "cd $( 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 ArgString end tell end tell
end tell
Here is the command I use:
if [[ -d $TM_SELECTED_FILE ]]; then TM_PATH="$TM_SELECTED_FILE" elif [[ -f $TM_SELECTED_FILE ]]; then TM_PATH="`dirname "$TM_SELECTED_FILE"`" else TM_PATH="`dirname "$TM_FILEPATH"`" fi
osascript <<EOF tell application "iTerm" activate if exists the first terminal then set myterm to the first terminal else set myterm to (make new terminal) end if tell myterm activate current session launch session "Default Session" tell the last session write text "cd '$TM_PATH'; clear; pwd" end tell end tell end tell EOF
-- FredB