Display dialog buttons


I’m having probably the most common problem ever, but I just couldn’t find an answer to my question.

So, I have a dialog and I want to get the button’s name the user pressed. I tried doing it a couple of ways - both gave me errors, which I couldn’t find an answer to.

First one:

set testAction to display dialog "blah blah blah" attached to window 1 buttons {"Ignore", "Quit"}
if button returned of testAction = "Quit" then
end if

Gave me this error:

The variable testAction is not defined. (-2753)

Second one:

set testAction to button returned of (display dialog "blah blah blah" attached to window 1 buttons {"Ignore", "Quit"})
if testAction = "Quit" then
end if

Gave me this error:

No result was returned from some part of this expression. (-2763)

I don’t know what I’m doing wrong, but I hope you do and that you can help me out.


You need to get rid of the attached to window 1 bit:

set testAction to button returned of (display dialog "blah blah blah" buttons {"Ignore", "Quit"})
if testAction = "Quit" then
end if

If are trying to make this a panel, you need to go into Interface Builder and make your own panel to attach to the window; you cannot use display dialog
as part of a panel.

Thanks, it worked. But now the dialog jumps into a random place - I mean, the dialog is not placed on the main window. I tried creating a panel, but that doesn’t seem to work out for me, because I need a window, that the user can’t pass - the user has to press a button, before he/she can move on. In my case, it tells the user to launch iTunes if it’s not running. But with panel, the user just clicks on the main window and the panel just stays behind the main window, so the user doesn’t even have to make a choice. But I need the user to make the choice. Is there any way to make the panel act like a dialog box? When I tried clicking the main window when the dialog box was running, it made this sound, that I can’t ignore the dialog box. Also, is there a possible way to attach the panel to the window, just like a dialog box?

I believe that whenever a panel is attached to a window, it immediately prevents the user from accessing anything but the panel in question. Here is how I have done that:

property monitorPanel : missing value

on DiskDitto()
	if monitorPanel is missing value then
		set monitorPanel to window "monitor"
		set contents of text field "monitor_text" of monitorPanel to ("Copying data from disc " & curr_a & " to Temporary Drive " & temp_Drive & "....")
		display panel monitorPanel attached to window "main"
	end if
close panel (window "monitor") with result 1
end DiskDitto

on panel ended theObject with result withResult
	if withResult = 1 then set monitorPanel to missing value
end panel ended

This usage is just to display progress of an event, but since you can build your panel any way you like, just build a window that has the responses available to the user, and collect that response into a global variable, or process the variable in the on panel ended handler.

I am certainly not an expert in this region, but there are a lot of threads here that you can find via Search that will help you out.

Good Luck,

Thanks a lot! I got it working in a lot better way than I would have using the dialog. Thanks again!