Jump to content
gingerbeardman

Option in workflow Open URL action to open in current/active browser

Recommended Posts

Posted (edited)

I use different, non-default browsers from time to time, and it's annoying when Alfred opens a page in the default browser when I do not have it open.

 

It would be great if there was an option for current/active browser.

Which I guess would be the most recently used browser if multiple are open?

Browser may not always be frontmost app.

 

957267637_Screenshot2020-05-21at09_29_07.png.c6dd470d0642fcc08b333fe084db7d15.png

Edited by gingerbeardman

Share this post


Link to post
Share on other sites

Easy to accomplish with a Workflow. Use a Run Script Action with language /usr/bin/osascript (AS) and code:

tell application "System Events" to set web_browser to name of first process whose frontmost is true
tell application web_browser to open location "https://example.com"

What you’ll use instead of https://example.com depends on what you were doing in the first place.

Share this post


Link to post
Share on other sites
25 minutes ago, gingerbeardman said:

What happens if the web browser is not frontmost? 

 

It opens in the default web browser.

Share this post


Link to post
Share on other sites
Posted (edited)
On 5/22/2020 at 12:26 PM, vitor said:

 

It opens in the default web browser.

 

Well, in that case it's not working for me as expected.

 

If a browser is frontmost it opens the URL in that browser. Great!

 

But if another app is front most, then the URL is not opened in any browser at all.

Edited by gingerbeardman

Share this post


Link to post
Share on other sites

Looks like some other apps also understand open location. Which then becomes a problem for your request as well, because how’s Alfred supposed to know what’s a web browser and what isn’t? Keeping an internal list of every web browser isn’t sensible, not the least of which because there are legitimate reasons for non-browser apps to open URLs (media players, for example).


Bottom line, the feature you’re asking for is best suited for a Workflow, and how it works depends on how much work you want to put into it. You’ve already seen a version in action, we can also add some code for another behaviour like “if the frontmost app isn’t one from list, open in app browser”. You’d have to be the one to maintain list in your personal workflow, as well as pick a default browser.

Share this post


Link to post
Share on other sites

That's fine by me. Thanks for your help!

 

Default browser always:

Safari

 

Browsers I mostly use:

Safari

Safari Technology Preview

 

other browsers i have on my system:

Chrome

Opera

 

Share this post


Link to post
Share on other sites
set browser_list to {"Safari", "Safari Technology Preview", "Google Chrome", "Opera"}
set default_browser to "Safari"

set web_address to "https://example.com"
tell application "System Events" to set front_app to name of first process whose frontmost is true

if browser_list contains front_app then
	tell application front_app to open location web_address
else
	tell application default_browser
		activate
		open location web_address
	end tell
end if

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...