Re: if-else statements
Re: if-else statements
- Subject: Re: if-else statements
- From: David Crowe via AppleScript-Users <email@hidden>
- Date: Sun, 24 Nov 2019 19:22:04 -0700
Here’s a version that works. Errors include:
- You cannot include line breaks in statements
- On the other hand, you need a line break after “then” in the “if” clause
unless it’s a single statement, and there’s no if clause
- You need to coerce “unluckyNumber” to a string (Applescript should be able to
do this, but often can’t)
I’m not defending any of these idiosyncracies of AppleScript.
set the dialog_result to (choose from list {1, 2, 3, 7} with title ("Pick the
lucky number"))
if the dialog_result is {7} then
display dialog "You win!" buttons {"OK"} default button {"OK"}
else
set unluckyNumber to item 1 of the dialog_result
display dialog (unluckyNumber as string) & " is an unlucky number."
end if
Regards,
David Crowe
> Message: 1
> Date: Sun, 24 Nov 2019 13:00:29 -0600
> From: ?iKel <email@hidden <mailto:email@hidden>>
> To: Applescript-users list <email@hidden
> <mailto:email@hidden>>
> Subject: if-else statements
> Message-ID: <email@hidden
> <email@hidden">mailto:email@hidden>>
> Content-Type: text/plain; charset="utf-8"
>
> Hi everyone,
> I am trying to learn how if-else statements work in AppleScript. When I run
> the script below I get "Expected end of line, etc. but found ?else?.? It
> seems like a simple script but I get this error and just really trying to
> learn the mechanics of if-else statements in AS. I appreciate the help and
> insight!
>
> set the dialog_result to ?
> (choose from list {1, 2, 3, 7} ?
> with title ("Pick the lucky number"))
> if the dialog_result is {7} then display dialog ?
> "You win!" buttons {"OK"} default button {"OK"}
> else
> set the unluckyNumber to the dialog_result
> display dialog the unluckyNumber & " is an unlucky number."
> end if
>
> Kind regards,
> Kell
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden