open embedded link in any app with non default browser

Hi, I want to right-click on a link (in mail, calender, etc) and have an option to open the link with a non-default browser. I've been googling this forever now and have found several solutions that are close but not close enough. I do not want a third party app like choosy. The links are not always the same so solutions that act on specific addresses are not sufficient. I want a right-click menu option to replace my old process of 1) right-clicking, 2) copying link and 3) pasting into preferred non default browser. The closest I have gotten is an automator service that will open a highlighted link in a chosen browser using an applescript or shell script: https://discussions.apple.com/thread/7937074


This does not work unless the actual address link is highlighted. For links embedded in emails where a link is available but the address is not visible or not easily highlightable, how can I achieve the same action? Is there some automator piece to capture the link below the mouse without it being highlighted? If I have to copy the link first, that won't really save me any time from the process I'm already using.


thanks

Mac Pro, macOS 10.14

Posted on Oct 20, 2020 10:54 AM

Reply

Similar questions

9 replies

Oct 21, 2020 6:15 AM in response to jdpes

The secondary menus in an application (including Finder) are hardwired to the design of that application, and not user configurable. Thus, no browser picker, as you might have in the Finder Open With sub-menu.


It may be possible with a custom Automator Quick Action to right-click on an application link, be presented with a list of browsers to choose from, and launching the link in the selected browser. I have not written this, so uncertain without coding and testing if it is feasible, or consists of unexpected issues.


Since I have wanted something like this on n-tuple occasions, I may (without a timetable) see what I can develop.

Oct 29, 2020 2:16 PM in response to jdpes

I wrote a test AppleScript here to verify that I can get the name of the default browser, and launch a hard-coded URL in that browser window, whether Safari, Firefox, Brave, or Chrome. The script pops a dialog with browser names to choose from, and then opens the URL in the selected browser.


The best that you can hope for is to select the entire URL that you want to have browser choice, and then pick a browser from a pop-open menu. You will not be able to right-click, or single-click a URL to open another browser because that would have to be incorporated into the viewing application's code.

Nov 2, 2020 7:41 AM in response to VikingOSX

I tried this and it works on visible links, but what can I do about links that are not visible? The ones where the link only becomes visible after a few seconds with the mouse hovering over them? I don't know what these are called but they are my main concern and unfortunately, the new quick action does not appear when I right click on them (presumably because the link never gets highlighted).


Many thanks

Oct 30, 2020 2:26 PM in response to jdpes

Here is the good news.

  1. You can right-click on a link in an application (which does the same as dragging over the link to select it), and then from that application's Services menu, select the name of the Quick Action to process that link.
  2. The Quick Action starts with an advisory list of browser names, and then runs a validate_browser function that returns a list of browsers that are actually installed.
    1. This list appears for you to choose your browser, and the current default browser is highlighted.
    2. Once a browser is selected, and you click OK, that browser will open with the URL presented in it.
  3. The AppleScript/Objective-C handlers (validate_browser, find_default) work correctly on Mojave and Catalina.


Bad news

  1. I cannot effectively control how many browser tabs, or windows are opened by the Quick Action. Worse, it is not consistent between Mojave 10.14.6 and Catalina 10.15.7. This might be controlled using compiled Objective-C or Swift applications with more fine-grained controls than allowed in AppleScript, but that is out of scope here.
  2. Although you can assign a unique keyboard shortcut to the Quick Action in System Preferences : Keyboard panel : Shortcuts : Services, the shortcut may or may not work when you want it too — causing the fallback use of the application's services menu to trigger the Quick Action. Nothing I can do to fix that either. Apple's wobbly tech.


The Quick Action header looks like:


And the browser selection list selector could look like this if all of the browsers were installed.


The code that replaces the Quick Action's Run AppleScript action contents are in two parts in the following two replies, due to the nonsensical, 5000 character hosting site limitations.

Oct 30, 2020 2:27 PM in response to VikingOSX

Part 1

use framework "Foundation"
use framework "AppKit"
use AppleScript version "2.4" -- Yosemite++
use scripting additions

property NSArray : a reference to current application's NSArray
property NSString : a reference to current application's NSString
property NSFileManager : a reference to current application's NSFileManager
property NSURL : a reference to current application's NSURL
property NSWorkspace : a reference to current application's NSWorkspace

on run {input, parameters}
	
	set browser_list to {"Safari", "Firefox", "Brave Browser", "Google Chrome"}
	-- the QA will not even work if a complete URL is not selected
	set thisURL to (input as text)
	
	set valid_browsers to my validate_browser(browser_list) as list
	set default_browser to my find_default() as list
	
	set browser_choice to (choose from list valid_browsers with title "Selectable Browser List" with prompt "Choose your preferred browser to open the link item. The default browser is pre-selected." default items default_browser as list without multiple selections allowed and empty selection allowed) as text
	
	if browser_choice is false then
		display dialog "User Cancelled application."
		return
	end if
	
	tell my application browser_choice
		activate
		try
			-- because some browsers (e.g. Firefox, Brave, etc.) open two windows
			-- this behaves differently on Mojave 10.14.6 and Catalina 10.15.7
			close window 2
		end try
		tell window index 1
			open location thisURL
		end tell
	end tell
	return input
end run


Oct 30, 2020 2:28 PM in response to VikingOSX

Part 2


on validate_browser(blist)
	-- dynamically shrink browser list if browser not installed
	set nsm_ab to (NSArray's arrayWithArray:blist)'s mutableCopy()
	repeat with ab in (nsm_ab as list)
		-- construct browser application path (e.g. /Applications/Safari.app, etc.)
		set nsmStr to (NSString's stringWithString:"/Applications/")'s mutableCopy()
		(nsmStr's appendString:ab)
		(nsmStr's appendString:".app")
		
		set installed to (NSFileManager's defaultManager()'s fileExistsAtPath:nsmStr) as boolean
		if not installed then
			(nsm_ab's removeObject:ab)
		end if
	end repeat
	return nsm_ab as list
end validate_browser

on find_default()
	-- use arbitrary URL to to detect default browser name that would open it...
	set aurl to NSURL's URLWithString:"https://www.apple.com"
	set appPath to ((NSWorkspace's sharedWorkspace)'s URLForApplicationToOpenURL:aurl)'s absoluteString()
	return (appPath's lastPathComponent()'s stringByDeletingPathExtension()) as list
end find_default


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

open embedded link in any app with non default browser

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.