Jump to content

Open search query url in new browser window, not new tab?


bo9

Recommended Posts

Is there a way to input settings for my workflow that would allow a search query url to open in a “new browser” window. At this time, I am able to open it in a "new tab", but it would be much better for my result to show up in a new window.

 

Thank you for any help. FYI, I am a newbie, so the layperson replies would be much appreciated. 

Link to comment

Thank you Vítor for the help. 
 

I use both Safari and Chrome. 
 

So when we complete a search query through the Alfred search bar, say for a YouTube video, open the Alfred bar, then type yt (space) and then the search words, then when I hit enter, it opens the YouTube video search in a new tab, in the same browser window, however I’d like for that search result to open up in a new tab but also in a new browser window.

Link to comment

The first thing to understand is that you can’t do this with the default custom searches, you must recreate the ones you want in a Workflow because you’ll need to run code to open the new browser window.

 

14 hours ago, bo9 said:

I’d like for that search result to open up in a new tab but also in a new browser window.


So you want it twice with one run?

Link to comment
17 hours ago, bo9 said:

I use both Safari and Chrome.

 

This makes the code more complex, because in addition to asking the browser to open the window now it also needs to know which browser to do it for. Make a Run Script Action with Language /usr/bin/osascript (JavaScript), and in Script, paste:

 

const frontmost_app_name = Application('System Events').applicationProcesses.where({ frontmost: true }).name()[0]
const frontmost_app = Application(frontmost_app_name)
frontmost_app.includeStandardAdditions = true

const chromium_variants = ['Google Chrome', 'Chromium', 'Opera', 'Vivaldi', 'Brave Browser', 'Microsoft Edge']
const webkit_variants = ['Safari', 'Webkit']

if (chromium_variants.some(app_name => frontmost_app_name.startsWith(app_name))) {
  frontmost_app.Window().make()
} else if (webkit_variants.some(app_name => frontmost_app_name.startsWith(app_name))) {
  frontmost_app.Document().make()
} else {
  throw new Error('You need a supported browser as your frontmost app')
}

function run(argv) { frontmost_app.openLocation(argv[0]) }

 

That takes in whatever URL you send from the previous object and opens it in a new tab in the frontmost browser app, whatever that is (again, not Firefox).

 

If you want it to open in a new tab and in a new window, use this instead:

 

function run(argv) { 
  const frontmost_app_name = Application('System Events').applicationProcesses.where({ frontmost: true }).name()[0]
  const frontmost_app = Application(frontmost_app_name)
frontmost_app.includeStandardAdditions = true

  const chromium_variants = ['Google Chrome', 'Chromium', 'Opera', 'Vivaldi', 'Brave Browser', 'Microsoft Edge']
  const webkit_variants = ['Safari', 'Webkit']

  if (chromium_variants.some(app_name => frontmost_app_name.startsWith(app_name))) {
    frontmost_app.openLocation(argv[0]) 
    frontmost_app.Window().make()
  } else if (webkit_variants.some(app_name => frontmost_app_name.startsWith(app_name))) {
    frontmost_app.openLocation(argv[0]) 
    frontmost_app.Document().make()
  } else {
    throw new Error('You need a supported browser as your frontmost app')
  }

  frontmost_app.openLocation(argv[0])
}

 

Link to comment

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
×
×
  • Create New...