2012-01-19 108 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將會減少麻煩拖着我到法院:-)