I am playing around with JavaScript for Automation on OS X Yosemite.
I am trying to open up a new tab in the terminal application. Here is what I've got so far:
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
The Terminal.windows.at(0).tabs
is essentially an array. It has a .push
method. I assumed that I could use the following statement to add a tab to the window:
Terminal.windows.at(0).tabs.push(new Tab());
but it throws a very general error:
Error -10000: AppleEvent handler failed.
The documentation is severely lacking and I'm thinking that this JavaScript for automation thing was just a gimik to get JavaScript developers onboard.
Note: I've seen AppleScript solutions that essentially just tell the System Events
Application to press Command + T to open up a new tab. That feels very hacky and makes Command + T hardcoded in there.
You can emulate the shortcut for one new tab. Also need declare the target tab
Look the example with two or more tabs