title: Open new Terminal Tab with OS X JavaScript for Automation
body: <p>I am playing around with JavaScript for Automation on OS X Yosemite.</p>
  
  <p>I am trying to open up a new tab in the terminal application. Here is what I've got so far:</p>
  
  <pre><code>var Terminal = Application('Terminal);
  var Tab      = Terminal.Tab;
  
  // Activate the Terminal App, creates a new window if there isn't one already
  Terminal.activate();
  
  // This contains all the windows
  Terminal.windows;
  // This contains the first window
  Terminal.windows.at(0) // alternatively, Terminal.windows[0]
  
  // This contains the tabs in the first window
  Terminal.windows.at(0).tabs
  </code></pre>
  
  <p>The <code>Terminal.windows.at(0).tabs</code> is essentially an array. It has a <code>.push</code> method. I assumed that I could use the following statement to add a tab to the window:</p>
  
  <pre><code>Terminal.windows.at(0).tabs.push(new Tab());
  </code></pre>
  
  <p>but it throws a very general error:</p>
  
  <pre><code>Error -10000: AppleEvent handler failed.
  </code></pre>
  
  <p>The documentation is severely lacking and I'm thinking that this JavaScript for automation thing was just a gimik to get JavaScript developers onboard.</p>
  
  <p>Note: I've seen AppleScript solutions that essentially just tell the <code>System Events</code> Application to press Command + T to open up a new tab. That feels very hacky and makes Command + T hardcoded in there.</p>