bo9 Posted February 9, 2022 Share Posted February 9, 2022 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
vitor Posted February 9, 2022 Share Posted February 9, 2022 Welcome @bo9, It depends entirely on your browser. You need to ask it specifically to open a new window with the search. Here’s an example which searches Google with Safari. If you need something different, please specify throughly what you want to accomplish and which browser you’re using. Quick note: if it’s Firefox, no luck. Link to comment
bo9 Posted February 10, 2022 Author Share Posted February 10, 2022 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
vitor Posted February 10, 2022 Share Posted February 10, 2022 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
bo9 Posted February 10, 2022 Author Share Posted February 10, 2022 Quote Yes. I have the workflows created and at this time they open the search results with the correct URL, but what do I need to add to the workflow to have them open in a "new browser window" rather just a "new tab" Link to comment
vitor Posted February 10, 2022 Share Posted February 10, 2022 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
cocoaaa Posted May 19 Share Posted May 19 (edited) Hi @vitor, I'm hoping to address the same need as the OP and have tried your code, but it seems to be limited to the case where a browser app is the current front most app. How should I modify the code to make it work even when a browser app is NOT the front most app? To be more specific, here are my concrete user scenarios: ## Case1: I am reading a pdf document, and want to search something on my default browser. (Note: Unlike the OP, I want the search to be just done in my default browser.) I want my search to be returned in a new window. ## Case2: I have a URL which can be acquired from my snippet (eg. I have a snippet `,,dn` set to "https://roamresearch.com/page/{date}" ) and I want to be able to open this URL in a new window. I've been hoping to implement this workflow for some time, and would really appreciate your help. Thank you! Edited May 19 by cocoaaa Link to comment
Stephen_C Posted May 19 Share Posted May 19 I wonder whether an Automation Task might help you. There are three that may be relevant (depending what your default browser is): Open in New Safari Window, Open in New Chromium Browser Window and Open in New Webkit Browser Window. Stephen Link to comment
cocoaaa Posted May 20 Share Posted May 20 Thanks a lot, @Stephen_C! These will do for what I need:) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now