2016-03-17 164 views
0

我正在創建一個小程序,我的一個功能是一本字典。我需要一種方式來分割主題,但由於某種原因,我的代碼無法工作。我不斷收到錯誤「Expected」else「等,但發現」end tell「。」此代碼:修復腳本編輯腳本爲蘋果腳本

set math_list to {"math", "Math"} 
set science_list to {"science", "Science"} 
set history_list to {"History", "history", "Social Studies", "social studies", "socialstudies"} 
set reading_list to {"writing", "reading", "grammar", "Grammar", "Reading"} 
set no_list to {"no", "not really", "I am ok", "I am good", "I am good"} 
set complete_list to reading_list & math_list & science_list & no_list & history_list 

tell application "SpeechRecognitionServer" 
    set theResponse to listen for complete_list with prompt "Would you like to search under the subject math, science, history, or reading" 
     if theResponse = "writing" then 
      set theResponse to "reading" --Otherwise you would get a very weird sentence 
     else if theResponse = "grammar" then 
      set theResponse to "reading" --Otherwise you would get a very weird sentence 
    if (math_list contains theResponse) then 
     say "Opening Google Chrome" 
     launch application "Google Chrome" 
    else if (science_list contains theResponse) then 
     say "Opening Google Chrome" 
     launch application "Google Chrome" 
    else if (history_list contains theResponse) then 
     say "Opening Google Chrome" 
     launch application "Google Chrome" 
    else if (reading_list contains theResponse) then 
     say "Opening Google Chrome" 
     launch application "Google Chrome" 
    else if (no_list contains theResponse) then 
     say "Ok then" 
    end tell 
end tell 

回答

1

if else塊與end if結束。不適用於end tell

+0

謝謝,這有助於很多! –

2

你還會發現在重複的結論,即只需輸入端,告訴,或者如果部分將自動被編譯成所需的正確類型結束:

tell app "itunes" 
repeat 5 times 
if exists playlist "Purchased" then 
play track 7 of playlist "Purchased" 
end 
end 
end 

隨後被編譯成:

tell application "iTunes" 
    repeat 5 times 
     if exists playlist "Purchased" then 
      play track 7 of playlist "Purchased" 
     end if 
    end repeat 
end tell 

學習使用這種輸入代碼的風格將加快您的生產並大大減少錯誤和問題。

祝你好運,

+0

謝謝,這有助於很多! –

0

這是爲我工作的答案。謝謝克雷格 - 史密斯:

你還會發現在重複的結論,即只需輸入端,告訴,或者如果部分將自動被編譯成所需的正確類型結束:

告訴應用「iTunes」的 重複5次 如果存在播放列表「購買」然後 播放軌跡播放列表「購買」 結束 結束 結束 7隨後被編譯成:

告訴應用程序「iTunes」的 重複5次 如果存在播放列表「購買」然後 播放軌跡播放列表的7「購買」 結束時,如果 端重複 端告訴 學習使用的輸入代碼風格會加快您的生產,大大降低了錯誤和問題。

祝你好運,