【问题标题】:Google Chrome doesn't open URL with AppleScriptGoogle Chrome 无法使用 AppleScript 打开 URL
【发布时间】:2012-08-19 03:46:30
【问题描述】:

我设置的是一个 AppleScript,它通过几个选项询问您要打开哪个网站,为了简单起见,我只列出了一个选项,Google。这是当前代码:

if the_button = "Google" then
    site = "http://www.google.com"
    tell application "Google Chrome"
        launch
        tell window 1
            make new tab with properties {URL:site}
            repeat while loading of active tab
                delay 0.1
            end repeat
        end tell
        activate
    end tell

它会在谷歌浏览器中打开一个新标签,但不会在 URL 栏中放置任何内容或重新加载/加载或任何内容。我试过这个:Script Safari 5.1 to open a tab 但是,没有任何效果。我正在使用 Mac OS X Lion 10.7.4 和 Google Chrome 版本 21.0.1180.79。请帮忙!

【问题讨论】:

    标签: macos google-chrome editor applescript


    【解决方案1】:

    它适用于我,但不适用于 Chrome 没有打开的窗口或所有窗口都最小化的情况。在这些情况下,您可以添加 reopen 命令来打开新的默认窗口或取消最小化窗口。

    set site to "http://www.google.com"
    tell application "Google Chrome"
        reopen
        activate
        tell window 1
            make new tab with properties {URL:site}
        end tell
    end tell
    

    另一种选择可能是使用do shell script "open " & quoted form of "http://google.com" & " -a Google\ Chrome" 之类的东西。它通常更接近浏览器的默认行为。

    【讨论】:

      【解决方案2】:

      你就不能这样做吗?

      tell application "Google Chrome"
          activate
          set theSite to "http://www.google.com/"
          open location theSite
      end tell
      

      “打开位置”命令是标准添加的一部分,适用于所有 Mac 应用程序。这是在任何 Mac 应用程序中打开网站的默认方式。您可能会注意到 Safari 的 AppleScript 字典甚至不包含打开网站的方法——它只是使用标准的“打开位置”命令,您可以在 Standard Additions 字典中找到该命令。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-22
        • 2020-11-25
        • 1970-01-01
        • 2013-10-18
        • 2020-04-11
        • 1970-01-01
        相关资源
        最近更新 更多