The ITLoginItem function(s) will easily set an app to autolaunch at login.
authorKent Sutherland <ksuther@ithinksw.com>
Mon, 17 May 2004 22:36:16 +0000 (22:36 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Mon, 17 May 2004 22:36:16 +0000 (22:36 +0000)
ITLoginItem.h [new file with mode: 0755]
ITLoginItem.m [new file with mode: 0755]

diff --git a/ITLoginItem.h b/ITLoginItem.h
new file mode 100755 (executable)
index 0000000..2bd02a8
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ *  ITLoginItem.h
+ *  ITFoundation
+ *
+ *  Created by Kent Sutherland on Sun May 16 2004.
+ *  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <Foundation/Foundation.h>
\ No newline at end of file
diff --git a/ITLoginItem.m b/ITLoginItem.m
new file mode 100755 (executable)
index 0000000..fe49255
--- /dev/null
@@ -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