• 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: Using results of dialogs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using results of dialogs?


  • Subject: Re: Using results of dialogs?
  • From: "koenig.yvan" <email@hidden>
  • Date: Fri, 16 May 2014 22:48:28 +0200


Le 16/05/2014 à 22:27, Alex Hall <email@hidden> a écrit :

Hi all,
I'm writing a script for a friend. It first prompts for a string, then for a selection from a list, then another string. On each dialog I have a check to be sure the user didn't cancel, which i just added. Now that I have that, though, the line after the check, where I grab the result, gives me an error that "result" is undefined. Do the results of these prompts go away after one use?

Here's my code. I've placed a double percent sign on the line that throws the error.

set btn_ok to "OK"
set btn_next to "Next"
set btn_cancel to "Cancel"
set btnList_nextCancel to {btn_next, btn_cancel}

display dialog "Enter the name of the folder to be searched. Capitalization does matter: " default answer "Sent" with title "Folder to Search" buttons btnList_nextCancel default button 1 cancel button 2
if button returned of result = btn_cancel then
return false
end if
%% set targetMailbox to text returned of result as text



When the instruction if button returned of result = btn_cancel then
is executed, the variable result no longer contain your dialog answer, it contains the result of the test.

In fact, the test upon Cancel is useless.
As you defined the cancel button in your instruction (cancel button 2), the cancel choice will never be reported in your code.

Given that, you may use :
set btn_ok to "OK"
set btn_next to "Next"
set btn_cancel to "Cancel"
set btnList_nextCancel to {btn_next, btn_cancel}

display dialog "Enter the name of the folder to be searched. Capitalization does matter: " default answer "Sent" with title "Folder to Search" buttons btnList_nextCancel default button 1 cancel button 2
set targetMailbox to text returned of result as text


If the test was really useful, you would have to code :

set btn_ok to "OK"
set btn_next to "Next"
set btn_cancel to "Cancel"
set btnList_nextCancel to {btn_next, btn_cancel}

set myAnswer to display dialog "Enter the name of the folder to be searched. Capitalization does matter: " default answer "Sent" with title "Folder to Search" buttons btnList_nextCancel default button 1 cancel button 2
if button returned of myAnswer = btn_cancel then
return false
end if
set targetMailbox to text returned of myAnswer as text

Run this late version from the script editor and look at the Events log issued when you hit Cancel (or press Escape).
You will get :

tell application "AppleScript Editor"
display dialog "Enter the name of the folder to be searched. Capitalization does matter: " default answer "Sent" with title "Folder to Search" buttons {"Next", "Cancel"} default button 1 cancel button 2
--> error number -128

Résultat :

error "Annulé par l’utilisateur." number -128

which is exactly what is also done by the "stripped" version.

Yvan KOENIG (VALLAURIS, France) vendredi 16 mai 2014 22:48:23




 _______________________________________________
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

  • Follow-Ups:
    • Re: Using results of dialogs?
      • From: Alex Hall <email@hidden>
References: 
 >Using results of dialogs? (From: Alex Hall <email@hidden>)

  • Prev by Date: Using results of dialogs?
  • Next by Date: Re: Using results of dialogs?
  • Previous by thread: Using results of dialogs?
  • Next by thread: Re: Using results of dialogs?
  • Index(es):
    • Date
    • Thread