Question

I've been looking into launchd and launchctl, but don't see how the former is intended for one-time tasks.

Let's say this app's user enters some details for a task to be run in the future. (They could add several at different times.) If using launched, I assume the app would create and save a plist and then load that. The plist's ProgramArguments could contain specific details of the task (which could change for future runs). The app would need to load one for each time? Would the app need to clean up (remove) the completed plist?

The calendar seems to be an alternative, however using the alert > open program feature seems to have issues.

Is there another alternative? Something built into Cocoa possibly?

All ideas greatly appreciated.

Was it helpful?

Solution

It seems there are multiple ways to accomplish this 'do-later' task . My goal was to use Objective-C and Cocoa as a solution. Initially, I had worries about 'blocking' the main thread in some way. It turns out NSTimer is one answer to the question. I ended up using:

NSTimer *timer = [[NSTimer alloc] initWithFireDate:date
                                          interval:0.1
                                            target:self
                                          selector:@selector(startSomeMethod:)
                                          userInfo:info
                                           repeats:NO];

to 'fire' a task at a later time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top