Designated Cancel Buttons Don't Cancel: Error Number --128 Feeble

I have changed one of the example enhanced window scripts that came with the supplied documentation to match the scenario of my script that fails constantly. Even with those changes the cancel buttons in the example script work as expected.

In my script cancel buttons should cancel too but they don’t. In the mentioned example script they do. The cancel buttons were not only those of DialogToolKit+ but of the stock Standard Additions.

In fact, any error escapes the traps. User cancelled should abort a loop but in my case it has no effect.

  1. If the script is told to use scripting additions (and, hence, Standard Additions) why does the display alert dialog’s cancel button not cancel even though the log does show User cancelled: error number -128 raised?
  2. If I specifically created a cancel button for the DialogToolkit’s enhanced window with create buttons why does choosing Cancel not raise User cancelled: error number -128 and go blank?

What have I done wrong?

My script is as follows:

use AppleScript version "2.4"
use scripting additions
use script "Dialog Toolkit Plus"

property _Values : {}
property LabelTextPerson : "Choose a person"
property LabelTextCompany : "Choose a company"


repeat
makePrompt()
try
	set ChoicesMade to {}
	repeat with i from 1 to the number of items in _Values
		set ChoicesInfo to {labelText:"", LabelChoice:""}
		if _Values's item i's contents is LabelTextPerson then set {ChoicesInfo's labelText, ChoicesInfo's LabelChoice} to {LabelTextPerson, _Values's item (i - 1)'s contents}
		if _Values's item i's contents is LabelTextCompany then set {ChoicesInfo's labelText, ChoicesInfo's LabelChoice} to {LabelTextCompany, _Values's item (i - 1)'s contents}
		if ChoicesInfo is not {labelText:"", LabelChoice:""} then set end of ChoicesMade to ChoicesInfo
    end repeat
	
	
	if ChoicesMade's item 1's LabelChoice = ChoicesMade's item 2's LabelChoice and ChoicesMade's item 1's LabelChoice = "Click to choose" then
		display alert "No contact was chosen. Choose at least one of a person or company, or cancel the workflow." as warning buttons {"Cancel", "Choose"} default button 2 cancel button 1
		
	else
		exit repeat
	end if
end try
end repeat


on makePrompt()
set MaxLabelWidth to max width for labels {LabelTextPerson, LabelTextCompany}

try
	set {_popup, popupLabel, PopupToBottom, PopuptoLeft} to ¬
		create labeled popup {"Click to choose", "Choose Me", "No Me", "No ME!"} ¬
			bottom 50 ¬
			left inset 2 ¬
			popup width MaxLabelWidth + 1 / 3 * (MaxLabelWidth) ¬
			max width MaxLabelWidth * 2 ¬
			label text LabelTextCompany ¬
			popup left MaxLabelWidth ¬
			initial choice 1
	
	
	set {_popup_2, popupLabel_2, PopupToBottom, PopuptoLeft} to ¬
		create labeled popup {"Click to choose", "Choose Me", "No Me", "No ME!"} ¬
			bottom PopupToBottom + 1 / 2 * (PopupToBottom) ¬
			popup width MaxLabelWidth + 1 / 3 * (MaxLabelWidth) ¬
			max width MaxLabelWidth * 2 ¬
			label text LabelTextPerson ¬
			popup left MaxLabelWidth ¬
			initial choice 1
	
	
	set {_TheButtons, _buttonsWidth} to ¬
		create buttons {"Cancel", "Choose"} ¬
			cancel button 1 ¬
			default button 2 ¬
			with equal widths
	
	
	
	set _Values to the first list of (display enhanced window ¬
		¬
			¬
				¬
					"Add E-mail addresses to the contacts" buttons _TheButtons ¬
		acc view width 350 ¬
		acc view height 180 ¬
		acc view controls {_popup, popupLabel, _popup_2, popupLabel_2})
on error errMsg number errNum
	return "Enhanced window completed with an error." & return & return & "Error " & errNum & "," & return & "Error says: " & errMsg
end try
end makePrompt

Because you’re telling it not to by putting it in a try block.

Because you’re telling it not to by putting it in a try block. Try just calling that handler, and you will see it returns the error details.