As well as the idle handler, with Yosemite you can also use timers in stay-open scripts. You just schedule a timer, and it will call a specified handler in your script after a specified delay. It's mostly fairly simple:
use framework "Foundation"
current application's NSTimer's scheduledTimerWithTimeInterval:2.0 target:me selector:"timerFired:" userInfo:(missing value) repeats:true
The time interval is obvious, the target is the script containing the handler, selector is the name of the handler, which must take a single argument of the timer itself, and repeats specifies whether it should run once or repeatedly until invalidated. So with the above, you might have a handler like:
on timerFired:theTimer
set theResult to display dialog "The timer fired" buttons {"Enough Already", "Keep it Up"} default button 2 giving up after 1
if button returned of theResult is "Enough Already" then theTimer's invalidate()
end timerFired:
That should be pretty obvious. And the beauty of this approach, like that of using idle handlers, is that no resources are being consumed during the delay.
But the catch -- and isn't there always one -- is that the script needs to be running in the foreground. That's always the case in applets, but it's rarely the case in script editors. In Script Editor, you can force the issue using control-command-R, or holding the control key so that Run in the Script menu changes to Run in Foreground. In ASObjC Explorer, you check the Run in foreground checkbox.
To avoid accidentally running it not in the foreground, precede the timer by this code:
if not (current application's NSThread's isMainThread()) as boolean then
display alert "This script must be run from the main thread." buttons {"Cancel"} as critical
error number -128
end if
And yes, it can be done via a script library in Mavericks. It's a bit more complicated, but there's a sample you can download from the ASObjC Explorer Web page.