Skip to content

Instantly share code, notes, and snippets.

@zzz6519003
Created August 28, 2014 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzz6519003/e4e1d613ac3978f3b81a to your computer and use it in GitHub Desktop.
Save zzz6519003/e4e1d613ac3978f3b81a to your computer and use it in GitHub Desktop.
mac app Start at login
-(void) addAppAsLoginItem {
NSString * appPath = [[NSBundle mainBundle] bundlePath];
// This will retrieve the path for the application
// For example, /Applications/test.app
CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:appPath];
// Create a reference to the shared file list.
// We are adding it to the current user only.
// If we want to add it all users, use
// kLSSharedFileListGlobalLoginItems instead of
// kLSSharedFileListSessionLoginItems
LSSharedFileListRef loginItems = LSSharedFileListCreate(
NULL, kLSSharedFileListSessionLoginItems, NULL);
if (loginItems) {
// Insert an item to the list.
LSSharedFileListItemRef item =
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemLast,
NULL, NULL, url, NULL, NULL);
if (item){
CFRelease(item);
}
}
CFRelease(loginItems);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment