【问题标题】:Apple Script Syntax errorApple 脚本语法错误
【发布时间】:2012-01-19 02:31:55
【问题描述】:

运行以下脚本时:

on run
  tell application "Safari"
    set allWins to every window
    set allTabs to {}
    repeat with currWin in allWins
      set allTabs to allTabs & every tab of currWin
    end repeat
    repeat with currTab in allTabs
      try
        if ((characters -10 thru -1 of (title of currTab as string)) as string) = "Google Music" then set musicTab to currTab
      end try
    end repeat
    tell musicTab
        execute javascript "SJBpost(\"playPause\");"
    end tell
  end tell
end run

收到语法错误Expected end of line but found identifier.javascript 突出显示。

我正在使用 automator 并尝试按照this 文章为谷歌音乐创建热键。

【问题讨论】:

    标签: safari applescript


    【解决方案1】:

    您可能需要更仔细地阅读linked article

    如果您使用的是 Safari,请将第一行中的“Google Chrome”更改为“Safari”,将单词 title(靠近中间)更改为 name,并将倒数第三行的单词 execute去做。

    因此尝试替换:

    tell musicTab
        execute javascript "SJBpost(\"playPause\");"
    

    与:

    tell musicTab to do javascript "SJBpost('playPause');"
    

    您也没有遵循该段change the word title (near the middle) to name 的第二条指令。通过所有这些更改,它变成:

    on run
      tell application "Safari"
                        ^^^^^^
        set allWins to every window
        set allTabs to {}
        repeat with currWin in allWins
          set allTabs to allTabs & every tab of currWin
        end repeat
        repeat with currTab in allTabs
          try
            if ((characters -12 thru -1 of (name of currTab as string)) as string) = "Google Music" then set musicTab to currTab
                            ^^^             ^^^^                                      ^^^^^^^^^^^^
          end try
        end repeat
        tell musicTab to do javascript "SJBpost('playPause');"
                         ^^
      end tell
    end run
    

    删除包含^^^ 字符标记的三行,它们只是为了使其尽可能明显。

    根据 Kurt Rudolph 的说法,它现在称为 Google 音乐(不再处于 Beta 版),因此我们也更改了标签标题检测以匹配。

    不幸的是,您必须自己测试一下,因为我看到的只是:

    We're sorry. Google Music is currently only available in the United States
    

    大概是 RIAA 将我拖入法庭不会那么麻烦 :-)

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 2016-04-25
      • 2011-06-30
      • 1970-01-01
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多