Launch At Login Cocoa

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:

  1. Hook a button or segmented control up to an IBAction
  2. in the action load the launchController
  3. set the launch controller to launch at startup
  4. 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!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.