[TxMt] one more update to command line tool

otheraccount at verizon.net otheraccount at verizon.net
Mon Jan 17 09:18:17 UTC 2005


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




More information about the textmate mailing list