Hi :),
I would like to close window/alert after some time.
I tried add timer, something similar like for example “giving up” in display dialog, in NSAlert object, but it doesn’t work.
I have something like that:
property NSTimer : class "NSTimer"
property NSAlert : class "NSAlert"
property NSObject : class "NSObject"
set messageText to "You didn't choose folder !!!"
set infoText to "Please click on \"Choose destination Folder\" and choose a destination folder."
set alert to NSAlert's alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(messageText, "OK", "", "", infoText)
alert's setAlertStyle_(2)
set myTimer to NSObject's alert
NSTime's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1, myTimer, "functionTimer", missing value, true)
alert's runModal()
and i have error “[<NSObject 0x7fff70517468> valueForUndefinedKey:]: this class is not key value coding-compliant for the key alert.”.
What I do wrong or how to add timer to NSAlert object ??
Thanks in advance ;).
Model: MBP Early 2008
Browser: Safari 533.21.1
Operating System: Mac OS X (10.6)
You can’t setup the timer in the normal fashion because its selector will never be called until the alert is dismissed. This code should work to do what you want:
on applicationWillFinishLaunching_(aNotification)
set theAlert to current application's NSAlert's ¬
alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_("Message Text", "OK", "Cancel", "", "Informative Text")
set theTimer to current application's NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(5, me, "closeAlert", missing value, 0)
current application's NSRunLoop's mainRunLoop's addTimer_forMode_(theTimer, current application's NSModalPanelRunLoopMode)
set theResponse to theAlert's runModal()
log theResponse
end applicationWillFinishLaunching_
on closeAlert()
current application's NSApp's abortModal()
end closeAlert
If you have a copy of Shane Stanley’s Myriad Helpers it contains a couple of methods that allow you to create the kind of alerts you want.