Hi
hi you !
I’m a total newby to ASOC and i want to make a timer app.
here is my code i know it doesn’t work but i dk how to pass argument to the timer.
The datediff is here to check if the wait time is over or if there is still time.
thx for reading me
[code]on datedif_(a,b,c)
log a
log b
log c
end datedif_
on buttonpress_(sender)
set varA to current date
set varB to (do shell script “date +%s”) as integer
set varC to 180 – this is the waiting time in second
set alarmtimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1, me, “datedif:”, missing value, true)
end buttonpress_[/code]
[code]on datedif_(sender)
log item 1 of sender’s userInfo
log item 2 of sender’s userInfo
log item 3 of sender’s userInfo
end datedif_
on buttonpress_(sender)
set varA to current date
set varB to (do shell script “date +%s”) as integer
set varC to 180 – this is the waiting time in second
set alarmtimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1, me, “datedif:”,{varA,varB,varC}, true)
end buttonpress_[/code]
and where i should invalidate my timer ?
if you want an one shot timer set the repeats parameter to false.
Then the timer gets invalidated automatically.
You can invalidate a timer wherever you want.
The shell call can be replaced with
set varB to current application's NSDate's |date|()'s timeIntervalSince1970() as integer
thx for your answer Stefan !
I’m currenly struggling to get the firedate and if a timer is valid.
i’ve try
set alarmtimercond to alarmtimer’s firedate
and set alarmtimercond to alarmtimer’s valid
but it doesn’t work
Hi, the following should work. Not sure if you were just in a hurry when posting, but everything is case-sensitive in Objective-C. So “fireDate” is not the same as “firedate”
set alarmTimerFireDate to alarmTimer's fireDate()
set alarmTimerIsValid to alarmTimer's isValid()
Also, you will need to have something like this at the top of your AppDelegate.applescript if you don’t already so that your NSTimer variable is accessible globally across handlers:
well i’m a bad coder
thx for your answer !!
i got this message because i declare the timer after
2014-11-25 07:59:53.526 Timer[25962:1598399] *** -[AppDelegate gobutton:]: missing value doesn’t understand the “isValid” message. (error -1708)
now it’s working thx !!