Start my application when logging into desktop

Discussion in 'Mac Programming' started by satyam90, Oct 19, 2007.

  1. satyam90 macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    Hi,

    I am using XCode 2.4.1 on Mac Tiger.

    I have an application which I want to start it at the time of logging into Mac :apple:. I want to do it programatically by providing an option in my application like "Start application when logging". I don't want to set it from dock.

    Also I have user authentication in my application. In that if I want to provide an option to remember password, where can i store it. In windows I am storing in registry by encrypting it. In Mac how to achieve this.

    Please help me.

    Regards,
    Satyam.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    That is like saying, "I am using Visual Studio 2005". Doesn't really help. The API could be Carbon or Cocoa or AppleScript Studio or plain old standard C libraries. You need to post what language/API you're using.

    Either way, check out this page. The link for LoginItemsAE will work with Carbon or Cocoa.

    Doesn't really matter, but easiest method would be to use the same method of encryption you used in the Windows app and save it to the standard preferences using NSUserDefaults (Cocoa) or CFPreferences (Carbon).
     
  3. satyam90 thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #3
    sorry for not mentioning the environment in which i am working.

    I am working on Cocoa with Obj C.
    In the example LoginItemsAE, it is writted purely in C. how can i use that in my project and add the option to my application "start the application when logging in".
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Objective-C is a strict superset of C. You can use the C example as is
     
  5. satyam90 thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #5
    i couldn't understand how to use the example LoginItemsAE.
    instead, we can use following code like this:


    CFArrayRef prefCFArrayRef = CFPreferencesCopyAppValue(CFSTR("AutoLaunchedApplicationDictionary"), CFSTR("applicationID"));
    CFMutableArrayRef tCFMutableArrayRef = CFArrayCreateMutableCopy(NULL, 0, prefCFArrayRef);
    /* Modify tCFMutableArrayRef here */
    CFPreferencesSetAppValue(CFSTR("AutoLaunchedApplicationDictionary"), tCFMutableArrayRef, CFSTR("applicationID"));

    In the above code, how to know the "applicationID" ...........
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    Just use the class UKLoginItemRegistry provided in the link above. It's Cocoa and will do what you want.
     
  7. satyam90 thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #7
    Hi, great solution.

    I tried to use the files specified in "UKLoginItemRegistry".
    But I am getting following errors:

    Couldn't list login items error 1700
    Couldn't add login item error 1700
    Couldn't remove login in item error 1700

    How to solve this ???
     

Share This Page