0

I would like to make an Automator Service that will open any link in a different browser (i.e. Firefox) than default (Safari).

Precisely: I want to right click on any link in Mac OS and select a service that will open that link in a Firefox.

  • 1
    Unless the link text of the hyperlink is the same as the href attribute, then I believe that what you're asking for is not doable with default actions of an Automator Service. This is because when you right-click on a hyperlink, what gets passed to the Automator Service is the link text not the href attribute (URL), and as such there is no URL to pass to another action to be acted upon. E.g. right-clicking on Google passes "Google" to the service not the URL - i.e. <a href="url">link text</a> = <a href="https://www.google.com">Google</a> – user3439894 Feb 18 '18 at 14:59
1

You can use the Automator action Extract URLs from Text.

  • This does not work, it simply gets nothing on the output. – kobozy Feb 15 '18 at 20:11
0

Instead of using Automator to parse the text, use a Terminal (Bash) command to get the text you are looking for.

grep -o 'http://[^"]*' foobar.rtf

You can add this to Applescript

set varURL to do shell script "grep -o 'http://[^"]*' foobar.rtf"

The simpliest way to extract a URL and open a browser window to that URL is via Bash script:

#!/bin/bash

varURL=`grep -o 'http://[^"]*' ${1}`

open $varURL

I have a sample.rtf file that I used to test this. It's basically are Lorem Ipsum generated file with a URL embedded randomly in the text.

When I run the script,

$ ./urlxtract.sh sample.rtf

it opens my default browser at the URL it found. To open it in a different browser, just replace the open line in the script with the following:

open -a "Firefox.app" $varURL
  • I need to put this into a service, as this seems to me the simplest way how to open an URL in a different browser, but I do not know how to do that. – kobozy Feb 15 '18 at 20:13
  • I understand and it works in Terminal, but not in automator Service. Even when I use the service just to run the file with the richtext as input, it opens nothing, just Firefox itself. It seems like the service does not get the link in the richtext input as it should. What I want: right click on any link in mail and select a service i.e. "Open in Firefox" -> the URL from that link should open in defined browser. What I use: an automator service with input as richtext in any application -> the service has only 1 action Run shell script with following code: ./urlxtract.sh "$@" – kobozy Feb 16 '18 at 8:51
  • You need to put that requirement in your question because as it's written, you are running a Bash command (osascript is called from Bash) – Allan Feb 16 '18 at 11:59
  • I am sorry, but I don't understand. Which requirement do you mean? – kobozy Feb 16 '18 at 12:20
  • What I want: right click on any link in mail and select a service. This requirement is completely different than what you are asking. You want to open a link you right click on it and open it with a different browser; it has nothing to do with rich text. This is a textbook definition of the XY Problem – Allan Feb 16 '18 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .