Pages

Thursday, September 23, 2010

Open Terminal Here

OpenTerminalHere is a very useful AppleScript: http://www.entropy.ch/software/applescript/
The source code, probably, may look so:
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 this_item in these_items
my process_item(this_item)
end repeat
end open



-- this subroutine does the actual work
--
on process_item(this_item)
set the_path to POSIX path of this_item
repeat until the_path ends with "/"
set the_path to text 1 thru -2 of the_path
end repeat
tell application "Terminal"
if (count of windows) is 0 then
do script with command "cd " & quoted form of the_path
else
if front window is busy then
--Can be tested by looking at a manpage or running top in terminal.app
tell application "Terminal" to activate
tell application "System Events" to tell process "Terminal" to ¬
keystroke "t" using command down
end if
do script with command "cd " & quoted form of the_path in window 1
end if
activate
end tell
end process_item
Or so:
on run
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
close
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end run
An update versions are available on james david low:
OpenTerminalHere and AntHere

You can find more:
Enhanced Open Terminal Here, for Leopard

Here is an Objective-C project "cdto":
http://code.google.com/p/cdto/downloads/list

No comments:

Post a Comment