• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: if-else statements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: if-else statements
  • Next by Date: Getting AppleScript Finder dictionary. back Where is Finder?
  • Previous by thread: Re: if-else statements
  • Next by thread: Getting AppleScript Finder dictionary. back Where is Finder?
  • Index(es):
    • Date
    • Thread