Is it possible to take something like this:
if doc contains "Translate results into my language" then
set TabStrokes to TabStrokes + 1
end if
if doc contains "did you mean" then
set TabStrokes to TabStrokes + 1
end if
if paragraphs 10 thru 13 of doc contains "Translate" then
set TabStrokes to TabStrokes + 1
end if
and turn it into something like this:
if doc contains "Translate results into my language" or if doc contains "did you mean" or if paragraphs 10 thru 13 of doc contains "Translate" then
set TabStrokes to TabStrokes + 1
end if
or even:
if doc contains "Translate results into my language" or "did you mean" then
set TabStrokes to TabStrokes + 1
end if
if paragraphs 10 thru 13 of doc contains "Translate" then
set TabStrokes to TabStrokes + 1
end if
This is just an example from my script. What i’m trying to get at is can you combine multiple “if” statements together? Thanks.
Between the “if” and the “then” you can have any number of logical tests, but not multiple ifs leading to a single then.
if (8 < 7 or 6 > 5) and 9 > 10 then
set Ans to "No Dice"
else if "ABCD" does not contain "B" then
set Ans to "OK"
else
set Ans to "SNAFU"
end if
Ok thanks. It just really makes my script look messy.
I found out that you CAN in fact have multiple if’s combined. Here are some examples:
if doc contains "as an Error caused by YouTube, we cannot deliver" and attempts is 0 then
set x to "woo!"
end if
if doc contains "Translate results into my language" or "did you mean" then
set TabStrokes to TabStrokes + 1
end if
if doc does not contain "processing" or "as an Error caused by YouTube, we cannot deliver" or "Invalid URL" or "link this mp3" then
if retry is 1 then
[more script]
end if
end if
Hi, drummerof13.
Your first example is correct and is what Adam showed you. The other two are incorrect and won’t produce the results you’re expecting. All conditions within an ‘if’ statement must be complete:
if (doc contains "Translate results into my language") or (doc contains "did you mean") then -- NB. 'doc contains' in both conditions.
set TabStrokes to TabStrokes + 1
end if
if (doc does not contain "processing") or (doc does not contain "as an Error caused by YouTube, we cannot deliver") or (doc does not contain "Invalid URL") or (doc does not contain "link this mp3") then
if retry is 1 then
-- [more script]
end if
end if
-- Or slightly more efficiently:
if not ((doc contains "processing") and (doc contains "as an Error caused by YouTube, we cannot deliver") and (doc contains "Invalid URL") and (doc contains "link this mp3")) then
if retry is 1 then
-- [more script]
end if
end if
-- Or, if there are no other conditional statements within the outer one:
if not ((doc contains "processing") and (doc contains "as an Error caused by YouTube, we cannot deliver") and (doc contains "Invalid URL") and (doc contains "link this mp3")) and (retry is 1) then
-- [more script]
end if
But they did EXACTLY what i wanted them to do. I just ran them again to double check. As they are (once you define the variables), it completes the task that is contained by the ifs.
set doc to "did you mean"
set TabStrokes to 0
if doc contains "Translate results into my language" or "did you mean" then -- incorrect original
set TabStrokes to TabStrokes + 1
end if
TabStrokes
set doc to "did you mean"
set TabStrokes to 0
if doc contains "Translate results into my language" or doc contains "did you mean" then -- correct version
set TabStrokes to TabStrokes + 1
end if
TabStrokes
Oooooh ok, I must not have checked the “did you mean”. Sorry.