display alert/dialog woes

I’d like to display a simple two button dialog or better yet an alert with the stop sign icon, attached to the main window panel.

i’ve looked at all the Studio examples and they are so unnecessarily complicated. I don’t want to define a panel in IB, or load stuff from NIBs, etc.

so far the only thing that comes close to working is the standard dialog that’s not attached:

set theReply to display dialog ts buttons {“Abort”, “Continue”} default button “Continue” with icon 0 --attached to window “Main”
if button returned of theReply is “Abort” then set continueok to false

If you add the “attached” parameter, I understand that the reply will come from another handler:

on dialog ended theObject with reply theReply
– Set the values returned in “theReply”
end dialog ended

The problem with that is, it won’t wait for the dialog to end before going on.

This SORT OF works with the above handler and a global variable for theReply set:

set theReply to {}
display dialog ts buttons {“Abort”, “Continue”} default button “Continue” with icon 0 attached to window “Main”
repeat
if theReply ≠{} then exit repeat
end repeat
if button returned of theReply is “Abort” then set continueok to false

but that is very stilted using the repeat loop to wait like that.

Isn’t there a simple way to show an attached alert panel with a couple of buttons and get the response?

It’s actually quite easy to display a panel in Xcode…

set thePanel to window "theWindow" display panel thePanel attached to window "mainWindow"
As for the buttons, you can use on clicked for that.

on clicked theObject if the name of theObject = "continueButton" then --continue else if the name of theObject = "abortButton then close panel (window of theObject) end if end clicked
Hope I helped.

well it helps somewhat, thanks. but you still have to populate the panel with a message, with an icon, etc, etc. where do you get the stop icon?

i just want to do a normal alert dialog, except as a panel, shouldn’t be so difficult.

edit: besides, using a panel as a dialog as described still leaves the problem of how to get the script to wait for a response before continuing. I just want to show a message and give the chance to abort a subroutine.

I’ve no idea mate. You can check the Interface builder application for them…I know they’re there when you create a new Carbon .nib

ok… i found out how to use “display alert” properly, and it is relatively simple, and you don’t have to design a panel to do it. you have to connect “alert ended” to the window you are attatching the the alert dialog to in IB.

the action you want to take is then handled in the alert ended handler, as follows:

main code:

display alert “Removing Tracks and Deleting Files” as critical message (“You are about to remove all unchecked tracks in the current selection and from the library, and move their files to the trash.”) default button “Continue” alternate button “Abort” attached to window “main”

on alert ended theObject with reply theReply
–display dialog (name of theObject as string)
if button returned of theReply is “Continue” then
– dothatthing () of me
end if
end alert ended

Two remaining problems:

  1. what if you wanted to use different alerts also attached to window main with the same buttons? name of theObject = “” or is empty or something. how would you identify which alert called the alert ended handler?

  2. why doesn’t “as warning” work? (show a stop sign or something?) it doesn’t work properly in the display alert example either. But critical does.

PS: totally unrelated, but what’s with some of the example script posted here that has a bunch of diamond symbols with ? in them? You can’t copy and paste them, and the link to paste the code in script editor doesn’t work.

Sweet.

As for the wierd symbols, they’re to keep the formatting. You can use replace to copy one of them in there and replace all of them with nothing, then compile it.