修复applescript的脚本编辑器脚本

时间:2016-03-17 19:46:53

标签: performance optimization applescript helper

我正在创建一个小程序,我的一个函数是字典。我需要一种方法来分割主题,但由于某种原因,我的代码将无法正常工作。我不断收到错误“预期”,“等等”,但发现“结束告诉”。“对于此代码:

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

3 个答案:

答案 0 :(得分:2)

您还会发现只需在重复结束时键入end,告诉或者是否会自动将该部分编译为所需的正确类型:

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

学习使用这种输入代码的方式可以加快您的生产速度并大大减少错误和问题。

祝你好运,

答案 1 :(得分:1)

if else块以end if结尾。不是end tell

答案 2 :(得分:0)

这个答案对我有用。谢谢克雷格史密斯:

您还会发现只需在重复结束时键入end,告诉或者是否会自动将该部分编译为所需的正确类型:

告诉app" itunes" 重复5次 如果存在播放列表"已购买"然后 播放播放列表中的第7个"已购买" 结束 结束 结束 随后汇编成:

告诉应用程序" iTunes"     重复5次         如果存在播放列表"已购买"然后             播放播放列表中的第7个"已购买"         万一     结束重复 结束告诉 学习使用这种输入代码的方式将加快您的生产速度并大大减少错误和问题。

祝你好运,