• 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: Simple Display Dialog confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Simple Display Dialog confusion


  • Subject: RE: Simple Display Dialog confusion
  • From: Rick Gordon <email@hidden>
  • Date: Thu, 17 Jul 2008 11:37:39 -0700

Title: RE: Simple Display Dialog confusion
A couple things to consider here:

First, to get the button returned, you need the button returned from something, so create a variable to load what's returned from the dialog, that way you have more than one crack at extracting values.

But also, "Cancel" basically generates an error and stops the script, so yu're never even getting there if the user choose "Cancel." So nest the dialog in a try clause, and use the "on error" to process or recover. Or don't name the button "Cancel."

set prompt to "Enter Date to import (MM/DD/YYYY)"
set mydate to current date
set today to (month of mydate as integer) & "/" & day of mydate & "/" & year of mydate
try
     set dialogresult to (display dialog prompt default answer today as string ¬
                buttons {"Cancel", "OK"} default button 2)
on error  --Cancel generates error.
   return "woof"
end try

set today to text returned of dialogresult

if button returned of dialogresult is "OK" then
        beep 4
else
        beep 2
end if

------------------

On 7/17/08 at 2:11 PM -0400, Gary Thompson wrote in a message entitled
"Simple Display Dialog confusion":

Hello,

Can someone tell me how to get the 'button returned' from the display dialog?

set prompt to "Enter Date to import (MM/DD/YYYY)"
set mydate to current date
set today to (month of mydate as integer) & "/" & day of mydate & "/" & year of mydate
set today to text returned of (display dialog prompt default answer today as string buttons {"Cancel", "OK"} default button 2)

This does not seem to work:
if button returned is "Cancel" then
        -- exit
else
        --do stuff
end if

Thanks, Gary

--
 
___________________________________________________

RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
WWW:   http://www.shelterpub.com
 _______________________________________________
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

References: 
 >Simple Display Dialog confusion (From: Gary Thompson <email@hidden>)

  • Prev by Date: Simple Display Dialog confusion
  • Next by Date: Re: Simple Display Dialog confusion
  • Previous by thread: Simple Display Dialog confusion
  • Next by thread: Re: Simple Display Dialog confusion
  • Index(es):
    • Date
    • Thread