Sweet Mac OS X Terminal Function

March 16, 2011

This is a nifty little trick I swiped from a Stack Overflow question.

Basically it adds a command to run any command in a new tab of the same terminal window you are currently in.

For example, this:

$ tabdo cd /tmp

would launch a new tab, then navigate to /tmp.

To get this trick, just put this in your ~/.bashrc

tabdo () {
        /usr/bin/osascript 2>/dev/null <<EOF
activate application "Terminal"
tell application "System Events"
    keystroke "t" using {command down}
end tell
tell application "Terminal"
    repeat with win in windows
        try
            if get frontmost of win is true then
                do script "$@" in (selected tab of win)
            end if
        end try
    end repeat
end tell
EOF
}

Here is a demo video, sorry it goes so fast, YouTube sped it up.

Categories: Geek
Tags: , , , , ,

Leave A Comment

Your email will not be published.

*