我试图在AppleScript中使用NSTimer作为“延迟”,换句话说,我想使用NSTimer只等待。
on buttonClicked_(sender)
log "Button is clicked"
NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(60, me, "timerFired:", "Whatever", false) -- I want to make this line work like "delay 60"!
log "Finished"
end buttonClicked_
on timerFired_(theTimer)
log "Timer Fired"
end timerFired_
但是,此代码输出如下:
: Button is clicked
: Finished
: Timer Fired
这是因为NSTimer启动但不等待下一个操作。
on buttonClicked_(sender)
log "Button is clicked"
delay 60
log "Finished"
end buttonClicked_
on timerFired_(theTimer)
log "Timer Fired"
end timerFired_
毕竟,我想在不改变格式的情况下将“延迟”替换为“NSTimer”。