2 questions related to NSTimer and 1 to Binding


I implemented the NSTimer like explained in the Shane book:

on applicationWillFinishLaunching_(notification)
set theTimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_ selector_userInfo_repeats_(60, me, “timerFired:”, “Whatever”, true)
end applicationWillFinishLaunching_

on timerFired_(someTimer)
log “here”
– do your stuff
– To stop, use the line:
– tell someTimer to invalidate()
end timerFired_

I have 3 questions:

  1. Suppose that the timerFired is called every 60 seconds and my stuff take 70 seconds to finish. In this case I would like that the app wait again 60 seconds starting from the end of process. following the example that I have implemented after my stuff finish to process it restart to process again because is invoked every 60 seconds.

  2. In the Shane example the string “Whatewer” is passed as parameter userInfo: How I can get this info (how to pass it) in the timeFired handler?

  3. To update a progress bar that process file I use bindings and property. All works good except that I need to use also the tell contentView to displayIfNeeded() otherwise some properties even if connected with binding are not update regulary.


You can’t use userInfo with ASOC. Just pass missing value.

I had a similar problem. Have a look at this : http://macscripter.net/viewtopic.php?id=36400


Actually with NSTimer, you can use the user info. In your example you would access the user info with the statement “someTimer’s userInfo()”.

As for the timing issue, I think you would have to use a non-repeating timer inside the timerFired method. If the work you are doing keeps further lines in that method from running until the work is done, you can just put a non-repeating timer as the last line in that method. It will be automatically invalidated once it fires, and then will be recreated after your work is done each time (you would take out the someTimer invalidate() line).



thanks for the info.

I modified all and seems to work :wink:

on applicationWillFinishLaunching_(aNotification)
set theTimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(5, me, “timerFired:”, missing value, false)
end applicationWillFinishLaunching_

on timerFired_(someTimer)
– Do Your Stuff
set theTimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(120, me, “timerFired:”, missing value, false)
end timerFired_

When app is launched the handler is called after 5 seconds for example.
After, the handler process images and when it finish wait 2 minutes (120 seconds) and call again the handler.
The last parameter is set to false.