recently I needed something that launched itself when a user logs in or restarts their computer.
Found this nifty little library: https://github.com/biocross/LaunchAtLoginController–with-ARC-
Basically, you load those two files into xcode, the do the following:
- Hook a button or segmented control up to an IBAction
- in the action load the launchController
- set the launch controller to launch at startup
- profit
In reality it looks like this:
Then in your IBAction do this:
NSSegmentedControl *segment = (NSSegmentedControl *) sender; NSInteger selectedSegment = [segment selectedSegment]; LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init]; BOOL launch = [launchController launchAtLogin]; if (selectedSegment == 0) { [launchController setLaunchAtLogin:YES]; } else { [launchController setLaunchAtLogin:NO]; }
Finally, make sure you include “#import “LaunchAtLoginController.h” or whatever you named the class in your header file.
That should be it. Get an action from the user, set the launch to yes and away you go!
“