Three changes.
I fixed the -w flag to await the closing of the editing window without any RETURN prompt. I stole the code from Marcin's otheraccount@verizon.net recent script. (What is Marcin's last name?)
I added a -t flag like bbedit, so you can name the piped input.
I also added the ability to pass a -u flag so filenames are treated as URLs. It then uses curl to decipher/download the filenames and passes the results to TM. Unfortunately, this only works for anonymous FTP and not most FTP/SFTP setups. I'm sure someone enterprising could do it, but it doesn't seem worth it unless TM saves files back to S/FTP. On the other hand, bbedit doesn't handle http at all! :)
Here is the current help file.
TextMate Command Line Tool usage: tm [-chtuw] filename [filename ...]
This tool opens files, directories, URLs or (with no filenames) standard input.
-c Create a new file. -h Show this help. -t Specify a title for piped input. Overrides other flags. -u Treat filenames as URLs (e.g. tm -u www.google.com). Uses curl. -w Waits for the edited file window to close before ending (for
external editing)
Here is (from what I can tell) lacking in comparison to bbedit.
- jump to line number (probably you'd want to use a command with output parsing anyway... see e.g. Perl>PerlErrors) - print (probably needs some Applescript... Marcin?) - FTP/SFTP (prob need support from TM itself)
The latest script is still at http://macromates.com/svn/Bundles/trunk/Scripts/tm.
best wishes, Eric
Uh, picking up again on this command-line-tool hacking, Eric suggested it should:
- jump to line number
This is no substitute for the real thing---just some GUI scripting, which isn't pretty---but a little thrown-together script for going to a particular line follows. I don't really fully know what I'm doing, so improvements are probably called for. It does what I wanted it to, sort of, but I suspect it's pretty fragile...
-----------------
#!/bin/sh
# # TextMate: Go to line. First argument is the line to go to; second is the # name of the file (full path is nec) and can be omitted, in which case the # front document is used. #
osascript -e 'tell app "TextMate.app" to activate'
# if a filename has been provided, open file or bring it to front (this is # better than just telling TM to open it only in that if the file is # already open as the front file in a project, it will open the # corresponding window rather than opening the file in a new window): if [ "$2" != "" ]; then osascript <<EofSCRIPTone
tell application "TextMate.app"
-- file to open: set target to "$2"
-- get its basename: set AppleScript's text item delimiters to "/" set targetBasename to last text item of target
-- loop thru windows, looking at their filenames: set AppleScript's text item delimiters to " " -- should be " —" but for some reason -- this is broken set found to false repeat with thisWin in windows
-- get filename of window contents: set winFile to first text item of (name of thisWin as string)
-- if this is it, bring it to front: if targetBasename is winFile then set index of thisWin to 1 set found to true end if
end repeat
-- if not found, open file in new window: if found is false then open POSIX path of target end if
end tell
EofSCRIPTone
fi
# go to line: osascript <<EofSCRIPT
tell app "System Events" tell process "TextMate" tell menu bar 1 tell menu bar item "Navigation" tell menu "Navigation" click menu item "Go to Line..." -- delay 1 end tell end tell end tell tell window "Go to Line" set value of text field 1 to "$1" -- delay 1 click button "Go to Line" end tell end tell end tell
EofSCRIPT
On Jan 17, 2005, at 10:18, otheraccount@verizon.net wrote:
Uh, picking up again on this command-line-tool hacking, Eric suggested it should:
- jump to line number
This is no substitute for the real thing---just some GUI scripting, which isn't pretty---but a little thrown-together script for going to a particular line follows. [...]
As I think I've previously revealed, I don't know much about AS, but isn't it possible to send raw apple events from AS? And to work with binary data structures?
If so, TextMate supports the Metro Werks External Editor API for opening a file at a given line [1].
Another option is to use the recently introduced URL-scheme with the open command.
And this is not me saying I won't do the promised command-line tool (and also, I'll fix it so that opening files which are in a project, will show up in that project instead of a new window)! ;)
[1] http://codingmonkeys.de/techpubs/externaleditor/pbxexternaleditor.html
Another option is to use the recently introduced URL-scheme with the open command.
Holy crap, of course! That butt-ugly GUI script was written before the URL-scheme appeared, and I hadn't fiddled with it since---this approach is clearly _vastly_ better. Thanks! (The only drawback I can see relative to the AppleScript monstrosity is that the URL thing currently won't work with files in a project window...)
At 4:18 AM -0500 1/17/05, otheraccount@verizon.net wrote:
Uh, picking up again on this command-line-tool hacking, Eric suggested it should:
- jump to line number
This is no substitute for the real thing---just some GUI scripting, which isn't pretty---but a little thrown-together script for going to a particular line follows. I don't really fully know what I'm doing, so improvements are probably called for. It does what I wanted it to, sort of, but I suspect it's pretty fragile...
I took Marcin's code and put it into the TM command line tool in SVN, so now it handle "jump to line number". I also added the ability to auto-detect whether to return to iTerm or Terminal.
http://anon:anon@macromates.com/svn/Bundles/trunk/Scripts/tm
( Note that there are un-reproducible glimpses of an odd bug where Applescript stops working with TM. If this happens, try ps aux | grep Textmate.service and kill the process. Then quit and restart TM. )
- Eric
ps. These hacks leave only the following in bbedit's command line tool lacking here (as far as I know): - print (probably needs some Applescript... Marcin?) - FTP/SFTP (prob need support from TM itself, though somebody somewhere put together a cool script...)
On Jan 17, 2005, at 23:41, Eric Hsu wrote:
( Note that there are un-reproducible glimpses of an odd bug where Applescript stops working with TM. If this happens, try ps aux | grep Textmate.service and kill the process. Then quit and restart TM. )
Ah, the problem is probably that since the service is also called TextMate, apple script commands are sent to the service (if it's running) instead of the actual application.
You can rename the service, you need to rename the file “TextMate.service/Contents/MacOS/TextMate” and update “TextMate.service/Contents/Info.plist” (the “CFBundleExecutable” key) accordingly.
Please let me know if the problem persists after this!