26

I have the following AppleScript that I wrote many years ago. I use this code to program buttons on my Harmony One universal remote to access online video services via Google Chrome. The code is not working. Google Chrome doesn't launch. I am running the code via RemoteBuddy. The code complies fine, but does not work.

Anyone have any thoughts on what might be the problem, or how I can improve the script to make it work?

tell application "System Events" to set open_applications to (name of everyprocess)
if (open_applications contains "Google Chrome") is true then
        tell application "Google Chrome" to quit
else
        tell application "Google Chrome"
                activate
                open location "http://xfinitytv.comcast.net"
        end tell
        delay 1
        tell application "Google Chrome" to activate
end if
ATLChris
  • 3,198
  • 7
  • 39
  • 65
  • I just tested your script. I changed "(name of everyprocess)" to "(name of every process)" and it works. Anyway, you can still use the code from my answer because it's faster without using "System Events". –  Feb 28 '14 at 23:36

3 Answers3

42

Try it this way:

tell application "Google Chrome"
    if it is running then
        quit
    else
        activate
        open location "http://xfinitytv.comcast.net"
        delay 1
        activate
    end if
end tell



Note: it's using the newer "Enhanced Application Model" (second line), more info here:
How to check in AppleScript if an app is running, without launching it - via osascript utility

Community
  • 1
  • 1
9
tell application "Google Chrome"
    open location "http://WEBSITEHERE.com"
end tell
Duckyy
  • 91
  • 1
  • 1
  • Can you please add some more context around your answer. Code-only or link-only answers are difficult to understand. It will help the asker and future readers both if you can add more information in your post. – RBT Dec 30 '16 at 00:46
  • Although elegant and simple, this always opens a _new_ tab for that URL and gives it focus. If you execute this more than once you will end up with multiple tabs for the same URL. Other answers above avoid this by closing the browser first, then reopening it (with no tabs). That has other drawbacks (e.g. where's my email and calendar tabs gone?). A better solution must exist. Anyone? – Fred Truter Dec 05 '19 at 09:59
1

osascript -e 'tell application "Google Chrome" to open location "http://yourlink.com.html"'

helmett
  • 11
  • 1