• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Add application to Startup Items?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add application to Startup Items?


  • Subject: Re: Add application to Startup Items?
  • From: Robert Cerny <email@hidden>
  • Date: Thu, 1 Jul 2004 14:16:38 +0200

Hi,
this is my code, which works well:

#define MAGICAUTOOPENKEYWORD @"AutoLaunchedApplicationDictionary"
#define HIDEKEY @"Hide"
#define PATHKEY @"Path"

- (void)insertToLoginItems:(NSString*)path hide:(BOOL)aValue
{
NSString *loginwindow = @"loginwindow";

NSUserDefaults *userDef;
NSMutableDictionary *dict;
NSDictionary *tempDict;
NSMutableArray *array;

userDef = [[NSUserDefaults alloc] init];

if( !(dict = [[userDef persistentDomainForName:loginwindow] mutableCopyWithZone: NULL]) )
dict = [[NSMutableDictionary alloc] initWithCapacity:1];

if( !(array = [[dict objectForKey:MAGICAUTOOPENKEYWORD] mutableCopyWithZone:NULL]) )
array = [[NSMutableArray alloc] initWithCapacity:1];

/* build entry */

tempDict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithBool:aValue], HIDEKEY,
path, PATHKEY,
nil];

/* add entry */

if( tempDict )
{
[array insertObject:tempDict atIndex:0];
[dict setObject:array forKey:MAGICAUTOOPENKEYWORD];
}

/* update user defaults */

[userDef removePersistentDomainForName:loginwindow];
[userDef setPersistentDomain:dict forName:loginwindow];
[userDef synchronize];

/* clean up */

[tempDict release];
[array release];
[dict release];
[userDef release];
}

HTH
Robert

On 1.7.2004, at 13:48, Gregory Weston wrote:

On Jun 30, 2004, at 11:21 PM, Mike Chambers wrote:

I have a simple status bar application and want to give the user the
option to have the app automatically started when they login.

I noticed that on 10.3.4 there is a StartUp Items section in the Users
section of System Preferences which has a few applications. How do I
add my application to that panel, and have it start automatically when
the user logs in.

I believe the proper answer here is: "Write to DTS and ask them for sample code to achieve it. There is no supported mechanism for doing so at this time."

I did it without going to DTS, but I'm not sure if it's appropriate to share the code given the above.

There is, obviously, a way of doing it and a few examples can be found on the web or via Google. Be warned, though, that they are not all reliable. I discovered that sometimes, depending on the mechanism you choose to interact with the prefs, the system will falsely report to you that the user has no login items defined and when you do what's necessary to add yours in that circumstance, you'll overwrite what they have. I think it may have something to do with the fact that somewhere along the line Apple changed OS X to create a group for every user.

All of the docs I have read suggest creating a StartupItem in:

/Library/StartupItems

but this folder appears to not exists on OS X anymore.

That folder does not exist by default, but you could create it. But that's not for the kind of things you're asking about.

G
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Add application to Startup Items? (From: Gregory Weston <email@hidden>)

  • Prev by Date: Re: Add application to Startup Items?
  • Next by Date: [iText-questions] absolute positioning in or inch
  • Previous by thread: Re: Add application to Startup Items?
  • Next by thread: [iText-questions] absolute positioning in or inch
  • Index(es):
    • Date
    • Thread