Apple脚本语法错误

时间:2012-01-19 02:31:55

标签: safari applescript

运行以下脚本时:

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文章之后为Google音乐创建热键。

1 个答案:

答案 0 :(得分:2)

您可能希望更仔细地阅读linked article

  

如果您正在使用Safari,请将第一行中的“Google Chrome”更改为“Safari”,将单词标题(中间附近)更改为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的说法,它现在被称为谷歌音乐(不再是测试版),所以我们也改变了标签标题检测,以便匹配。

你不得不自己测试一下,因为我看到的只有:

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

据推测,RIAA将我拖入法庭的麻烦更少: - )