Sunday, January 21, 2018

#1 2003-06-02 02:08:00 pm

Registered: 2003-05-16
Posts: 13

Defining conditions in "on alert ended"

I need to define the "on alert ended" handler to handle multiple alerts, each with different buttons and responses. As it stands, you can only have one handler for the event, so I need to execute the actions conditionally, but I can't find anything in Apple's documentation about how to tell the handler what to do for each individual alert. Basically, I need this line of code:


on alert ended theObject with reply theReply
   if [a certain alert which I don't know how to identify comes up]
       if button returned of theReply is alternateButtonTitle then
           tell application "Terminal"
               do script "sudo /usr/local/bin/vpn_uninstall" in window 1
               set frontmost of window 1 to true
           end tell
       end if
   else [if the other error comes up]
   end if
end alert ended

And the first alert is invoked by this line


set theReply to display alert dialogText as dialogType message dialogMessage default button defaultButtonTitle alternate button alternateButtonTitle attached to window "mainWindow"

Damien Sorresso

Filed under: terminal



#2 2003-06-06 07:08:10 am

From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Re: Defining conditions in "on alert ended"

You can define a global which will pass information to the "alert ended panel". Eg:


global panelType
global panelAuxiliarInfo

on clicked theObject --> eg, a button will display a panel or alert or whatever
if name of theObject is "button will display alert"
set panelType to "alert"
display alert whatever
end if

on alert ended theObject with reply theReply
if panelType is "alert" then
set infoINeed to panelAuxiliarInfo
end if

If you are displaying, eg, a panel attached to a window with buttons and text fields and you click OK (eg, a button), you can handle such button to define "panelAuxiliarInfo":


on clicked theObject
if name of theObject is "buttonOKOfPanel" then
set panelAuxiliarInfo to contents of text field "x" of window "I am a panel"
end if

So, thanks to the defined global, you can get later the value of "panelAuxiliarInfo", when you reach the "alert ended" handler.



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)