2012-01-19 110 views
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 found identifier.javascript突出显示。

我正在使用automator并尝试为this文章创建Google音乐的热键。

回答

2

您可能要多一点仔细阅读了linked article

如果您使用Safari浏览器,在第一线,以改变“谷歌浏览“Safari浏览器,”改字标题(近中间)来命名,并在倒数第三行上更改单词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将会减少麻烦拖着我到法院:-)