我正在尝试使用 NSTimer 作为 AppleScript 中的“延迟”,换句话说,我想使用 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”。