Tuesday, October 14, 2008

New tab in current directory (Terminal.app)

One of the most annoying things is when you have to open a new tab
in the current position. Say the shell in the current tab has x
as the current working directory and you want another shell already
in that directory. 
It seems there is no way to tell Terminal.app "open new tab"
from apple script. Mixing solutions found on the web, I came up with:

tell application "Terminal"
    set oldMem to (do shell script "pbpaste")
    set theTab to selected tab of the front window
    (do script "pwd | pbcopy" in theTab)
    set theText to (do shell script "pbpaste")
    tell application "System Events" ¬
        to tell process "Terminal" ¬
            to keystroke "t" using command down
    do script with command ¬
        "cd "& theText & ";clear "¬
        in selected tab of the front window

    do shell script "echo \""& oldMem & "\" | pbcopy"
end tell

Ugly, but works.

No comments: