打开网址并通过Applescript激活Google Chrome

时间:2014-02-28 22:57:43

标签: applescript

我有许多年前写过的AppleScript。我使用此代码编程我的Harmony One通用遥控器上的按钮,以通过谷歌浏览器访问在线视频服务。代码无效。谷歌浏览器无法启动。我通过RemoteBuddy运行代码。代码很好,但不起作用。

任何人都对可能出现的问题有什么想法,或者我如何改进脚本以使其发挥作用?

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

3 个答案:

答案 0 :(得分:26)

以这种方式尝试:

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



注意:它使用较新的“增强型应用程序模型”(第二行),更多信息请点击:
How to check in AppleScript if an app is running, without launching it - via osascript utility

答案 1 :(得分:2)

tell application "Google Chrome"
    open location "http://WEBSITEHERE.com"
end tell

答案 2 :(得分:0)

osascript -e'告诉应用程序“ Google Chrome”打开位置“ http://yourlink.com.html””