Script to open new tab on MAC terminal

In my dev environment I used to start many services every day manually, thinking about how to make my life easier I wrote a script that aggregates all scripts, however, each one was running on different terminals in a new window, something like:

open -a Terminal.app “/usr/local/Cellar/mongodb26/2.6.8/bin/mongod”

I didn’t like the solution with several windows open, so I added a small script to open each execution in different tabs:

#!/usr/bin/env bash

function openWithNewTab() {
TABNAME=$1
COMMAND_TO_EXEC=$2
osascript \
-e “tell application \”Terminal\”” \
-e “tell application \”System Events\” to keystroke \”t\” using {command down}” \
-e “do script \”printf ‘\\\e]1;$TABNAME\\\a’; $COMMAND_TO_EXEC\” in front window” \
-e “end tell” > /dev/null
}

#Going to a folder and list all files

openWithNewTab “Tab name” “cd ~/my_docs; ls -lsa”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s