PDA

View Full Version : Add/remove .app file to startup programatically




developer.in
Dec 19, 2008, 10:27 AM
Hi

In my mac application I want to give the user an option of starting the app on startup in application preferences.
How can I add or remove my application to startup programs programatically?
I am using Objective-C as the programming language.

Thanks



yellow
Dec 19, 2008, 10:28 AM
Startup as in /Library/StartupItems/?
or
Startup as in the user's Login Items?

developer.in
Dec 19, 2008, 10:53 AM
Startup as in /Library/StartupItems/?
or
Startup as in the user's Login Items?

As in user's Login items.

yellow
Dec 19, 2008, 11:02 AM
Not sure about programmatically, but here's what I use for AD attached Macs that won't open Login Items appropriately on cached credentials. Maybe it'll lead you in the right direction:

Make sure you have the latest version of Property List Editor installed (it's much easier than trying to accomplish this via command line, which I might detail here anyway). Be logged in as the user you want to fix, or as root, since you won't have the ability to read/write the file as anyone else.

Open the editor, and point it at /Users/username/Library/Preferences/loginwindow.plist
There should be an "AutoLaunchedApplicationDictionary" entry already. If not, create one (as an array).
Add a new child and it'll automatically be a number, make it Dictionary and open the twisty.
Add a new child to that number, name it "Hide", make it Boolean, and set to no (or yes, if you want it hidden).
Add a new sibling, name it Path, make it a String, and put in the full path to the object you want to start up at login. In comparison to other entries, you might see "AliasData". Don't worry about that, it will be created automatically.
Save and logout.
Log back in. The login item should fire correctly.

developer.in
Dec 19, 2008, 11:16 AM
Not sure about programmatically, but here's what I use for AD attached Macs that won't open Login Items appropriately on cached credentials. Maybe it'll lead you in the right direction:

Thanks. That did help. But is there any way I can open it as a source code file like we open a normal info.plist? Shows some garbled values when I tried. I wanted to see the the format.

yellow
Dec 19, 2008, 11:19 AM
Ah, plists were converted to binary files in Tiger (I think), where they were flat text before that.

plutil can be used to convert from bin/xml.

kainjow
Dec 19, 2008, 06:20 PM
For doing this programmatically this page should help: StartingMyAppOnStartup (http://www.cocoadev.com/index.pl?StartingMyAppOnStartup)

satyam90
Dec 24, 2008, 03:52 AM
I tried a lot with UKLoginRegistry on Mac Tiger. But didn't work. The same thing if I debug line by line it is working. When I run as an application its not working.