Jump to content

New tab instead of new window


Joost de Valk
 Share

Recommended Posts

Hey!

 

Loving the new automation tasks for getting current window from Safari and Chrome, but I'd really like to be able to explicitly open a new tab in both, instead of a new window. Is that an option?

Link to comment
Share on other sites

Here's a JXA script that should accomplish what I think you're looking for. You can implement this via the "run script' action. Make sure you select the /usr/bin/osascript (JavaScript) option to add the code into. If you want to do both, just create a loop over the browsers array.

var browsers = ["Safari", "Google Chrome"]
//for chrome -- use browsers[1] or just write the string
//for safari -- use browsers[0] or just write the string 
var app = Application(browsers[1])
app.includeStandardAdditions = true

var window = app.windows[0]
tab = app.Tab() //new tab
//NOTE if you want a specific url for that tab: tab = app.Tab({url: https://www.example.com})
window.tabs.push(tab) //add the tab to the array of current tabs
window.currentTab = tab //make this the current tab

 

Link to comment
Share on other sites

Welcome @Joost de Valk,

 

You just need the Open URL Action. Web browsers by default open URLs in new tabs.

 

@fwdalpha That won’t work universally. Webkit and Chromium browsers have different AppleScript dictionaries, in particular with respect to currentTab, which is named activeTab in Chromium browsers and you switch to it by passing the tab’s index, not the object. In short, that code will work for Safari but not Google Chrome. And you can remove the app.includeStandardAdditions line.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...