4

I'd like to create a service to open a link in Chrome. I already have this service installed: Safari Extension for right click menu: Open in Google Chrome?

This works if I right-click on selected text that is a URL. But it doesn't work if I right-click a link whose title is not a URL. For example, I'd like to right click a thread title at http://meh.com/forum and have have a command under Services to open that link in Chrome. The service referenced above doesn't show up in the Services contextual menu. Safari has a "Copy Link" menu item in the contextual menu. Is there a way to trigger that command from Automator or AppleScript?

  • I already have a shortcut to open the current page in Chrome, but in this case I can't open the page in Safari first because it resets the unread flags on the messages in the thread. – SSteve Dec 2 '14 at 20:36
  • Did you find an answer to this? – erotsppa Dec 9 '15 at 1:54
1

Try this code on Automator action "Run Javascript".

for Chrome

function run(input, parameters) {

    var app = Application("Google Chrome");
    app.includeStandardAdditions = true;

    var url = app.windows[0].activeTab.execute({
        javascript: 'window.getSelection().anchorNode.parentNode.href'
    });

    return url;
}

for Safari

function run(input, parameters) {

    var app = Application("Safari");
    app.includeStandardAdditions = true;

    var url = app.doJavaScript('window.getSelection().anchorNode.parentNode.href',{
        in: app.windows[0].currentTab
    });

    return url;
}

For example enter image description here

Right click on the link and select "Copy link to clipboard" service, then you can get the URL.

  • What needs to be done to include this code as a Service? – nohillside Oct 29 '15 at 8:20
-1

Build your actions as a Service (This is type of document you choose when you create a new automator workflow).

Relevant services should show up in the contextual menu under "Services" though you may need to turn them on under the "Shortcuts" tab of the Keyboard System preference pane (why there? I don't know).

  • I know how to make a Service. I'm sorry if that wasn't clear in my question. The problem is that I can't figure out how to invoke Safari's "Copy Link" menu item from the contextual menu. I tried assigning a keyboard shortcut to it in System Preferences but apparently that doesn't work with contextual menus. – SSteve Dec 2 '14 at 21:31

You must log in to answer this question.

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