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


Click here to return to the 'Alternative Applescript solution for Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Alternative Applescript solution for Terminal
Authored by: haighy on Nov 01, '04 07:59:22PM

Terminal is a bit weird in that (as far as I know) there's no explicit way to create a new window. However, just running a script without specifying a window will create a new one.

I wrote this little script, which I've attached to a trigger with Quicksilver. It creates a new window in the Terminal if it needs to, and switches to the directory of the frontmost window in the Finder.


tell application "Finder" to get POSIX path of (target of front window as string)
set mypath to the result
tell application "Terminal"
	if ((count windows) is 0) then
		do script ("cd " & quoted form of mypath)
		activate
		return
	end if
	
	if front window is busy then
		do script ("cd " & quoted form of mypath)
	else
		do script ("cd " & quoted form of mypath) in front window
	end if
	activate
end tell

Combined with Default Folder's "Reveal in Finder" command, you can jump from an open dialog box to the same directory in the terminal in just two keystrokes. UI and CLI cooperating in a symphony of...uh...goodness. Oh yeah, and if you bind a key in the shell to type something like "open ." you can jump from the terminal to the current working directory in the Finder, i.e. the opposite direction. This is what I use in my .zshenv:


bindkey -s "^[l" " open .\012"
Putting \012 (octal for enter) on the end of the binding means you can make the leap in one keystroke, in this case opt-L (technically meta-L I guess). Note that this works for zsh, I don't know how to do it in bash.



[ Reply to This | # ]
Alternative Applescript solution for Terminal
Authored by: Djehuti on Mar 08, '06 06:10:35PM
In bash, it's

	bind '"\M-l": "open .\012"'
Or you can just put

	"\M-l": "open .\012"
in your ~/.inputrc file.

[ Reply to This | # ]