From: Kent Sutherland Date: Mon, 17 May 2004 22:36:16 +0000 (+0000) Subject: The ITLoginItem function(s) will easily set an app to autolaunch at login. X-Git-Tag: v0.2~6 X-Git-Url: http://git.ithinksw.org/ITFoundation.git/commitdiff_plain/c40f5440e35326e867b0fa87ec9963d41205380c The ITLoginItem function(s) will easily set an app to autolaunch at login. --- diff --git a/ITLoginItem.h b/ITLoginItem.h new file mode 100755 index 0000000..2bd02a8 --- /dev/null +++ b/ITLoginItem.h @@ -0,0 +1,11 @@ +/* + * ITLoginItem.h + * ITFoundation + * + * Created by Kent Sutherland on Sun May 16 2004. + * Copyright (c) 2004 __MyCompanyName__. All rights reserved. + * + */ + +#include +#include \ No newline at end of file diff --git a/ITLoginItem.m b/ITLoginItem.m new file mode 100755 index 0000000..fe49255 --- /dev/null +++ b/ITLoginItem.m @@ -0,0 +1,52 @@ +/* + * ITLoginItem.c + * ITFoundation + * + * Created by Kent Sutherland on Sun May 16 2004. + * Copyright (c) 2004 __MyCompanyName__. All rights reserved. + * + */ + +#import "ITLoginItem.h" +#import "ITDebug.h" + +BOOL ITSetLaunchApplicationOnLogin(NSString *path, BOOL flag) +{ + NSUserDefaults *df = [NSUserDefaults standardUserDefaults]; + NSMutableDictionary *loginwindow; + NSMutableArray *loginarray; + FSRef fileRef; + AliasHandle alias; + NSData *aliasData; + + ITDebugLog(@"Set if MenuPrefs launches at login to %i.", flag); + [df synchronize]; + loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy]; + loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; + + //Create the alias data + FSMakeRefWithPath([path UTF8String], &fileRef); + FSNewAlias(NULL, &fileRef, &alias); + aliasData = [NSData dataWithBytes:&alias length:sizeof(alias)]; + + if (flag) { + NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys: + [[NSBundle mainBundle] bundlePath], @"Path", + [NSNumber numberWithInt:0], @"Hide", + aliasData, @"AliasData", nil, nil]; + [loginarray addObject:itemDict]; + } else { + int i; + for (i = 0; i < [loginarray count]; i++) { + NSDictionary *tempDict = [loginarray objectAtIndex:i]; + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { + [loginarray removeObjectAtIndex:i]; + break; + } + } + } + [df setPersistentDomain:loginwindow forName:@"loginwindow"]; + [df synchronize]; + [loginwindow release]; + return YES; +} \ No newline at end of file