Applescript: How to pass web address between browsers using a keyboard shortcut?

Discussion in 'Mac Programming' started by morbus, Dec 15, 2014.

  1. morbus macrumors newbie

    Joined:
    Nov 14, 2014
    #1
    I use Chrome on my Mac, and sometimes videos don't load - but in Safari they always load.

    It would be nice to have a shortcut like this: whenever I double click the address bar in Chrome while holding the apple key, I will send that address to Safari, Safari will load the page in a new tab and I will see the video.

    Does applescript have all the right APIs to make such a shortcut? If so, what are the key functions I should research?
     
  2. Sciuriware macrumors regular

    Sciuriware

    Joined:
    Jan 4, 2014
    Location:
    Gelderland
    #2
    And what's wrong with cut & paste? (Cmd/c - Cmd/v)?
    ;JOOP!
     
  3. morbus thread starter macrumors newbie

    Joined:
    Nov 14, 2014
    #3
    a) it is slower than the shortcut I described
    b) it does not teach me anything new
     
  4. Alrescha macrumors 68020

    Joined:
    Jan 1, 2008
    #4
    If this is your goal, why are you here instead of poking through the Safari and Chrome dictionaries in Script Editor? :)

    e.g., from the Safari dictionary: "URL (text) : The current URL of the document"

    so something like:
    Code:
    tell application Safari to set MyURL to URL of front document
    
    In order to invoke it from a keyboard shortcut, you may need to make it a service using Automator (which also has a helpful function called "Get Current Web Page from Safari" :)

    If you are new to Applescript then I recommend playing around with Automator to get your feet wet.

    Some more AppleScript examples:

    https://gist.github.com/vitorgalvao/5392178

    A.
     
  5. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #5
    Yep. I agree that a fairly simple AppleScript should be able to do the job for you.

    As other posters have commented, if you're looking for a learning experience then have a rummage through the scripting dictionaries of both Chrome and Safari using Script Editor. The info you need is probably in there. If you run into problems, show us your code and we'll help.

    Once you have your code sorted out then it's a question of how to trigger it. I'd suggest an Automator based service might be a cool way of doing it. Info on how to do that here:

    http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/

    Good luck, and feel free to ask questions once you've got some of the way!
     
  6. morbus thread starter macrumors newbie

    Joined:
    Nov 14, 2014
    #6
    Great - thanks guys, I've got enough info now to go to work on this. Good to a) know that it possible and not too complex and b) have some resources to start.
     

Share This Page