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


Click here to return to the 'Open a Terminal window at current Finder selection' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open a Terminal window at current Finder selection
Authored by: allanmarcus on Aug 19, '04 10:26:32AM
here's a modified version of Marc Liyanage's Open Terminal Here that does use the perl script. This one works more smoothly for both drag and drop and a click. I dragged in to my toolbar and it works great. It does have the "issue" that if you drag an app to it, it will open in the ".app" directory, but that's the expected behavior.

(*

	Open Terminal Here
	
	A toolbar script for Mac OS X 10.3
	
	Written by Marc Liyanage

	
	See http://www.apple.com/applescript/macosx/toolbar_scripts/ for
	more information about toolbar scripts.
	
	See http://www.entropy.ch/software/applescript/ for the latest
	version of this script.
	
	
	History:
	18-AUG-2004: Version 2.0 by Allan Marcus. uses posix path	
	30-OCT-2001: Version 1.0, adapted from one of the example toolbar scripts
	30-OCT-2001: Now handles embedded single quote characters in file names
	30-OCT-2001: Now handles folders on volumes other than the startup volume
	30-OCT-2001: Now handles click on icon in top-level (machine) window
	31-OCT-2001: Now displays a nicer terminal window title, courtesy of Alain Content
	11-NOV-2001: Now folders within application packages (.app directories) and has a new icon
	12-NOV-2001: New properties to set terminal columns and rows as the Terminal does not use default settings
	14-NOV-2001: Major change, now handles 8-bit characters in all shells, and quotes and spaces in tcsh
	18-NOV-2001: Version 1.1: Rewrite, now uses a temporary file  ~/.OpenTerminalHere to communicate
	the directory name between AppleScript and the shell because this is much more reliable for 8-bit characters
	
*)

property terminal_rows : 24
property terminal_columns : 90
property debug : true

-- when the toolbar script icon is clicked
--
on run
	tell application "Finder"
		activate
		try
			set this_folder to (the target of the front window) as alias
		on error
			set this_folder to startup disk
		end try
		my process_item(this_folder)
	end tell
end run

-- This handler processes folders dropped onto the toolbar script icon
--
on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to item i of these_items
		my process_item(this_item)
	end repeat
end open

-- this subroutine processes does the actual work
--
on process_item(this_item)
	set thePath to quoted form of POSIX path of this_item
	tell application "Terminal"
		activate
		do script with command "cd " & thePath
		tell window frontmost
			set custom title to this_item
		end tell
	end tell
end process_item




[ Reply to This | # ]
Open a Terminal window at current Finder selection
Authored by: klktrk on Aug 21, '04 12:09:54AM

Too bad you can't use this script with iTerm. I tried. Doesn't work.



[ Reply to This | # ]
Open a Terminal with either iTerm or Terminal
Authored by: klktrk on Aug 21, '04 02:18:59AM

Okay, so I figured out how to do it with iTerm:

(*

Open Terminal Here

A toolbar script for Mac OS X 10.3

Written by Marc Liyanage


See http://www.apple.com/applescript/macosx/toolbar_scripts/ for
more information about toolbar scripts.

See http://www.entropy.ch/software/applescript/ for the latest
version of this script.


History:
20-AUG-2004: Version 2.0.1 by Kristofer Widholm, can work with either iTerm or Terminal
18-AUG-2004: Version 2.0 by Allan Marcus. uses posix path
30-OCT-2001: Version 1.0, adapted from one of the example toolbar scripts
30-OCT-2001: Now handles embedded single quote characters in file names
30-OCT-2001: Now handles folders on volumes other than the startup volume
30-OCT-2001: Now handles click on icon in top-level (machine) window
31-OCT-2001: Now displays a nicer terminal window title, courtesy of Alain Content
11-NOV-2001: Now folders within application packages (.app directories) and has a new icon
12-NOV-2001: New properties to set terminal columns and rows as the Terminal does not use default settings
14-NOV-2001: Major change, now handles 8-bit characters in all shells, and quotes and spaces in tcsh
18-NOV-2001: Version 1.1: Rewrite, now uses a temporary file ~/.OpenTerminalHere to communicate
the directory name between AppleScript and the shell because this is much more reliable for 8-bit characters

*)

property terminal_rows : 24
property terminal_columns : 90
property debug : true
property terminalApp : "iTerm" --set to "Terminal" if you'd rather use that.
-- when the toolbar script icon is clicked
--
on run
tell application "Finder"
activate
try
set this_folder to (the target of the front window) as alias
on error
set this_folder to startup disk
end try
my process_item(this_folder)
end tell
end run

-- This handler processes folders dropped onto the toolbar script icon
--
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
my process_item(this_item)
end repeat
end open

-- this subroutine processes does the actual work
--
on process_item(this_item)
set thePath to quoted form of POSIX path of this_item
if terminalApp is equal to "iTerm" then
tell application "iTerm"
activate
try
set firstTerminal to (the first terminal)
on error
set firstTerminal to (make new terminal)
end try
tell firstTerminal
launch session "Default Session"


tell the last session

-- write some text
write text "cd " & thePath
end tell
end tell
end tell
else if terminalApp is equal to "Terminal" then
tell application "Terminal"
activate
do script with command "cd " & thePath
tell window frontmost
set custom title to this_item
end tell
end tell
end if
end process_item



[ Reply to This | # ]