Apple 脚本语法错误

发布于 2024-12-27 18:50:01 字数 882 浏览 2 评论 0原文

运行以下脚本时:

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 findidentifier. 并且 javascript 突出显示。

我正在使用 automator 并尝试为 google music 创建热键,如下 这篇文章

When running the following script:

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

received is the syntax Error Expected end of line but found identifier. and javascript becomes highlighted.

I'm using automator and trying to create hot keys for google music following this article.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡笑忘祈一世凡恋 2025-01-03 18:50:01

您可能需要更仔细地阅读链接的文章

如果您使用的是 Safari,请将第一行中的“Google Chrome”更改为“Safari”,将标题(靠近中间)一词更改为名称,并将倒数第三行中的“执行”一词更改为“Safari”要做的事。

因此,请尝试将:替换

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

为:

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

您也没有遵循该段落的第二条指令将单词标题(靠近中间)更改为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 Music(不再是测试版),因此我们也更改了标签标题检测以匹配。

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

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

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

You may want to read the linked article a little more closely:

If you're using Safari, change the 'Google Chrome' in the first line to 'Safari,' change the word title (near the middle) to name, and change the word execute on the third-to-last line to do.

Hence try replacing:

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

with:

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

You also haven't followed the second instruction of that paragraph change the word title (near the middle) to name. With all those changes, it becomes:

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

Remove the three lines containing ^^^ character markers, they're just there to make it as obvious as possible.

And, according to Kurt Rudolph, it's now called Google Music (no longer in Beta) so we've changed the tab title detection as well, to match.

You'll have to test this yourself unfortunately since all I see is:

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

Presumably where the RIAA would have less trouble dragging me into court :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文