Question: Oh my mac, whenever I start terminal I want to run a few commands, open another tab, cd into a certain dir, start a server on my local, and ssh into a remote server.

How do I do this automatically?

Thanks

Answer: 
You could write a shell script that does all that. And if you don't want to manually input your password when logging on to the SSH server, then you can put your key on the remote server as an authorized key not needing the password (if configured correctly of course).

[This page](http://lambie.org/2007/11/03/tabs-in-terminal-using-applescript-on-leopard/) shows how to use AppleScript to open terminal, give it focus, open 4 tabs etc. You could modify it for your purpose.

The following AppleScript activates the terminal, creates a new tab and executes "your\_command" (the script that does what you want) in the second tab:

```
on menu_click(mList)
    local appName, topMenu, r

    -- Validate our input
    if mList's length < 3 then error "Menu list is not long enough"

    -- Set these variables for clarity and brevity later on
    set {appName, topMenu} to (items 1 through 2 of mList)
    set r to (items 3 through (mList's length) of mList)

    -- This overly-long line calls the menu_recurse function with
    -- two arguments: r, and a reference to the top-level menu
    tell application "System Events" to my menu_click_recurse(r, ((process appName)'s (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
    local f, r

    -- `f` = first item, `r` = rest of items
    set f to item 1 of mList
    if mList's length > 1 then set r to (items 2 through (mList's length) of mList)

    -- either actually click the menu item, or recurse again
    tell application "System Events"
        if mList's length is 1 then
            click parentObject's menu item f
        else
            my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
        end if
    end tell
end menu_click_recurse

tell application "Terminal"
    activate
    my menu_click({"Terminal", "Shell", "New Tab", "Pro"})
    set window_id to id of first window whose frontmost is true
    do script "your_command" in tab 2 of window id window_id of application "Terminal"
end tell

```
Add the commands to your ~/.bashrc file and ensure it is runned each time you start the terminal:

Preferences > Shell > Startup > Mark: Run command and type: source ~/bashrc