Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. LSSharedFileListRef globalLoginItems = LSSharedFileListCreate(NULL, kLSSharedFileListGlobalLoginItems, NULL);
  2. if (globalLoginItems) {
  3. LSSharedFileListItemRef ourLoginItem = LSSharedFileListInsertItemURL(globalLoginItems,
  4. kLSSharedFileListItemLast,
  5. NULL, NULL,
  6. (CFURLRef)[[NSBundle mainBundle] bundleURL],
  7. NULL, NULL);
  8. if (ourLoginItem) {
  9. CFRelease(ourLoginItem);
  10. } else {
  11. NSLog(@"Could not insert ourselves as a global login item");
  12. }
  13.  
  14. CFRelease(globalLoginItems);
  15. } else {
  16. NSLog(@"Could not get the global login items");
  17. }
  18.  
  19. AuthorizationRef auth = NULL;
  20. AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth);
  21. LSSharedFileListSetAuthorization(globalLoginItems, auth);
  22.  
  23. AuthorizationItem right[1] = {{"system.global-login-items.", 0, NULL, 0}};
  24. AuthorizationRights setOfRights = {1, right};
  25. AuthorizationRef auth = NULL;
  26. AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth);
  27.  
  28.  
  29. AuthorizationCopyRights(auth, &setOfRights, kAuthorizationEmptyEnvironment,
  30. (kAuthorizationFlagDefaults
  31. | kAuthorizationFlagInteractionAllowed
  32. | kAuthorizationFlagExtendRights), NULL);
  33.  
  34. NSString * appPath = [[NSBundle mainBundle] bundlePath];
  35.  
  36. // This will retrieve the path for the application
  37. CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
  38.  
  39. LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListGlobalLoginItems, NULL);
  40. if (loginItems) {
  41. //Insert an item to the list.
  42. LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,kLSSharedFileListItemLast, NULL, NULL,url, NULL, NULL);
  43. if (item){
  44. CFRelease(item);
  45. }
  46. }
  47.  
  48. CFRelease(loginItems);
  49.  
  50. NSString * appPath = [[NSBundle mainBundle] bundlePath];
  51.  
  52. // This will retrieve the path for the application
  53. CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
  54.  
  55. // Create a reference to the shared file list.
  56. // We are adding it to the current user only.
  57. // If we want to add it all users, use
  58. // kLSSharedFileListGlobalLoginItems instead of
  59. //kLSSharedFileListSessionLoginItems
  60. LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
  61. if (loginItems) {
  62. //Insert an item to the list.
  63. LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,kLSSharedFileListItemLast, NULL, NULL,url, NULL, NULL);
  64. if (item){
  65. CFRelease(item);
  66. }
  67. }
  68.  
  69. CFRelease(loginItems);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement