Jump to content

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
Posted

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.

Posted
25 minutes ago, gingerbeardman said:

What happens if the web browser is not frontmost? 

 

It opens in the default web browser.

  • 2 weeks later...
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
Posted

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.

Posted

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

 

  • 2 weeks later...
Posted
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

 

  • 2 weeks later...

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...