gingerbeardman Posted May 21, 2020 Posted May 21, 2020 (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. Edited May 22, 2020 by gingerbeardman
vitor Posted May 21, 2020 Posted May 21, 2020 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.
gingerbeardman Posted May 22, 2020 Author Posted May 22, 2020 What happens if the web browser is not frontmost?
vitor Posted May 22, 2020 Posted May 22, 2020 25 minutes ago, gingerbeardman said: What happens if the web browser is not frontmost? It opens in the default web browser.
gingerbeardman Posted June 5, 2020 Author Posted June 5, 2020 (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 June 6, 2020 by gingerbeardman
vitor Posted June 11, 2020 Posted June 11, 2020 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.
gingerbeardman Posted June 15, 2020 Author Posted June 15, 2020 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
vitor Posted June 24, 2020 Posted June 24, 2020 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 gingerbeardman 1
gingerbeardman Posted July 11, 2020 Author Posted July 11, 2020 I love this function so much I wanted it everywhere and I eventually found this app (not created by me!) https://defaultbrowser.app you can set valid browsers, and a default, and any link opened will do so in your most recently active browser with your default as fallback.
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