0

I am creating a small program and one of my functions is a dictionary. I need a way to split the subjects though but for some reason my code won't work. I keep getting the error "Expected “else”, etc. but found “end tell”." for this code:

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 Answers 3

2

You will also find that simply typing end at the conclusion of a repeat, tell, or if section will automatically be compiled into the correct type of end needed:

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

is subsequently compiled into:

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

Learning to use that style of entering code will speed up your production and greatly reduce errors and problems.

Good luck,

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you this helps a lot!
1

An if else block ends with end if. Not with end tell.

1 Comment

Thank you this helps a lot!
0

This is the answer that worked for me. Thank you Craig Smith:

You will also find that simply typing end at the conclusion of a repeat, tell, or if section will automatically be compiled into the correct type of end needed:

tell app "itunes" repeat 5 times if exists playlist "Purchased" then play track 7 of playlist "Purchased" end end end is subsequently compiled into:

tell application "iTunes" repeat 5 times if exists playlist "Purchased" then play track 7 of playlist "Purchased" end if end repeat end tell Learning to use that style of entering code will speed up your production and greatly reduce errors and problems.

Good luck,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.