Created
August 28, 2014 14:46
-
-
Save zzz6519003/e4e1d613ac3978f3b81a to your computer and use it in GitHub Desktop.
mac app Start at login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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