2016-03-17 132 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“购买” 结束时,如果 端重复 端告诉 学习使用的输入代码风格会加快您的生产,大大降低了错误和问题。

祝你好运,