I often use QS to open a Terminal at a specific location. I have been
using Open Terminal Here. That script has originally been written as a
toolbar script by Marc Liyanage:
http://www.entropy.ch/software/applescript/

The version of Open Terminal Here I have been using is a modification:
http://hintsforums.macworld.com/showthread.php?t=81519

My routine has been like this:

1st pane: Item where I wanted the Terminal to open
2nd pane: Open With...
3rd pane: OpenTerminalHere

To me, this has advantages over "Go to Directory in Terminal" from the
Terminal Module: It will not open a new Terminal window; it will also
work on applications (going to the application folder) and files
(going to the folder where the file is located).

The disadvantage has been that it is a three step command. With very
few AppleScript knowledge but lots of trial and error, I have now
managed to modify Open Terminal Here into a custom Quicksilver action
(to be put in ~/Library/Application\ Support/Quicksilver/Actions ):


on open these_items
        repeat with this_item in these_items
                my process_item(this_item)
        end repeat
end open

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"
                activate
                if front window is busy then
                        tell application "System Events" to tell process 
"Terminal" to
keystroke "t" using command down
                        do script with command "cd " & quoted form of the_path 
in window 1
                        tell application "System Events" to keystroke return
                else
                        do script with command "cd " & quoted form of the_path 
in window 1
                end if
        end tell
end process_item


The tricky part has been the "keystroke return" line. It fixes what
appears to be some kind of focus issue: Without that line, and with a
busy Terminal window (for instance an man page, less, vim, top), the
script would open a new Terminal tab at the requested location.
Afterwards, however, the Quicksilver modifier-only activation would
not work. It only worked again after I did something on the Terminal.
Using "keystroke return" appears to be a painless way for doing so.
Occasionally -- but not always (why?) -- this will cause the newly
opened tab to have an extra prompt line, just as when you really type
return.

What causes that focus issue? Is there a more elegant fix?

--
grĂ¼ess
mach

Reply via email to