Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Re: Use Terminal's vi as default text editor' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Re: Use Terminal's vi as default text editor
Authored by: Uncle Asad on Mar 13, '08 07:25:50PM

When I'm writing an applet that duplicates a lot of code in its on run and on open handlers, I find it useful to prevent duplication and ease maintenance by making those handlers "stubs" that collect some information and then run the shared code in another method.

For example,

on run
	set inputfile to ""
	my launchVI(inputfile)
end run

on open inputfile
	my launchVI(inputfile)
end open

on launchVI(inputfile)
	ignoring application responses
		tell application "Terminal"
			activate
			tell application "System Events" to tell process ¬
				"Terminal" to keystroke "t" using command down
			if inputfile ≠ "" then
				do script "vi " & quoted form of POSIX path of inputfile ¬
					in selected tab of the front window
			else
				do script "vi " in selected tab of the front window
			end if
		end tell
	end ignoring
end launchVI

There's probably a way to eliminate the if/else, but it's late and I'm not thinking very hard right now ;)

[ Reply to This | # ]