Search code examples
javascriptmacosapplescriptosx-yosemitejavascript-automation

How can I open a new Chrome window with javascript automation in yosemite?


I'm trying to do something basic. I just want to open a new window and then in that window, open 2 tabs, using OSX Yosemite's new javascript bridge. I can't find docs that show how to do this:

ObjC.import("Cocoa");
chrome = Application("Google Chrome");
chrome.includeStandardAdditions = true
chrome.open("test1tab.com");
chrome.open("test2tab.com");

Solution

  • I'm ignoring the standardAddiions line, mostly because I used it and it returned an error when trying a basic beep(). Also note that I had to write out the full url for it to work!

    chrome = Application("Google Chrome");
    //chrome.includeStandardAdditions = true;
    win = chrome.Window().make();
    chrome.windows[0].tabs[0].url = "http://www.crgreen.com/index2.html";
    tab = win.tabs.push(new chrome.Tab());
    chrome.windows[0].tabs[1].url = "http://www.crgreen.com/boethos/";
    

    (p.s. I edited a junky version out, then saw you originally wanted 2 tabs, so here you go)