From 8d770173cee35e1b6139ee6ccb1511ccfa55a3c2 Mon Sep 17 00:00:00 2001 From: Alexander Strange Date: Sat, 3 Apr 2004 21:30:51 +0000 Subject: [PATCH 01/16] More work on ITAppleEventTools and also fix a compiler warning --- ITAppleEventTools.m | 21 ++++++++++++++++++++- ITByteStream.m | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index a236816..6eb927c 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -50,8 +50,27 @@ NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClas { } -NSAppleEventDescriptor *ITSendPlainAE(FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn) +NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn) { + AEDesc dest; + int pid; + + AppleEvent event, reply; + OSStatus cerr,cerr2,err; + NSAppleEventDescriptor *nsd, *nse, *nsr; + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { + ITDebugLog(@"Error getting PID of application."); + return; + } + cerr = AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest); + nsd = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&dest] autorelease]; + cerr2 = AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event); + nse = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&event] autorelease]; + if (!cerr2) [nse logDesc]; + err = AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); + nsr = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply] autorelease]; + [nsr logDesc]; + return nsr; } @implementation NSAppleEventDescriptor (ITAELogging) diff --git a/ITByteStream.m b/ITByteStream.m index e4607b4..664e1a0 100755 --- a/ITByteStream.m +++ b/ITByteStream.m @@ -61,6 +61,11 @@ return old; } +-delegate +{ + return delegate; +} + -(int) availableDataLength { int len; -- 2.20.1 From 8a2d5e51312c61db0e315eecb1e6ad4adc98d5da Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Thu, 22 Apr 2004 23:04:25 +0000 Subject: [PATCH 02/16] Dewarninging ITAppleEventTools --- ITAppleEventTools.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index 6eb927c..0b86b64 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -48,6 +48,7 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn) { + return nil; } NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn) @@ -58,9 +59,9 @@ NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,cons AppleEvent event, reply; OSStatus cerr,cerr2,err; NSAppleEventDescriptor *nsd, *nse, *nsr; - if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { + if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) { ITDebugLog(@"Error getting PID of application."); - return; + return nil; } cerr = AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest); nsd = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&dest] autorelease]; -- 2.20.1 From 2e8981e8a5d62b58f14f95c328a21756a6f6abf8 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Thu, 22 Apr 2004 23:08:30 +0000 Subject: [PATCH 03/16] Added the two other AE functions to the header. --- ITAppleEventTools.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ITAppleEventTools.h b/ITAppleEventTools.h index 5f67704..9f37807 100755 --- a/ITAppleEventTools.h +++ b/ITAppleEventTools.h @@ -11,6 +11,8 @@ #import extern NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn); +extern NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn); +extern NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn); @interface NSAppleEventDescriptor (ITAELogging) -(void) logDesc; -- 2.20.1 From d507320b5f6481480f7e0374e5e6a71b8fbdcb34 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Thu, 22 Apr 2004 23:39:38 +0000 Subject: [PATCH 04/16] ITSendPlainAE is now known as ITSendAE --- ITAppleEventTools.h | 2 +- ITAppleEventTools.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ITAppleEventTools.h b/ITAppleEventTools.h index 9f37807..5e41ab4 100755 --- a/ITAppleEventTools.h +++ b/ITAppleEventTools.h @@ -12,7 +12,7 @@ extern NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn); extern NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn); -extern NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn); +extern NSAppleEventDescriptor *ITSendAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn); @interface NSAppleEventDescriptor (ITAELogging) -(void) logDesc; diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index 0b86b64..da09a84 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -51,7 +51,7 @@ NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClas return nil; } -NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn) +NSAppleEventDescriptor *ITSendAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn) { AEDesc dest; int pid; -- 2.20.1 From feac8630679182f02220d997c433a31d7162f41c Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Sun, 25 Apr 2004 14:32:41 +0000 Subject: [PATCH 05/16] Fixed the AppleEvent tools to actually work. --- ITAppleEventTools.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index da09a84..e4bd45a 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -28,7 +28,7 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev return nil; } - berr = AEBuildAppleEvent(evClass, evID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, usendString); + berr = AEBuildAppleEvent(evClass, evID, typeProcessSerialNumber,psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, usendString); send = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&sendEvent] autorelease]; if (!berr) [send logDesc]; @@ -63,7 +63,7 @@ NSAppleEventDescriptor *ITSendAE(FourCharCode eClass, FourCharCode eID,const Pro ITDebugLog(@"Error getting PID of application."); return nil; } - cerr = AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest); + cerr = AECreateDesc(typeProcessSerialNumber,psn,sizeof(ProcessSerialNumber),&dest); nsd = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&dest] autorelease]; cerr2 = AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event); nse = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&event] autorelease]; -- 2.20.1 From c897ec0f7d3b828be34304109ddc6814328c0ac1 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Sun, 25 Apr 2004 15:14:15 +0000 Subject: [PATCH 06/16] ITSendAEWithString returns the AEDesc at index 1 of the resulting AEDesc, which is what contains data that we want. --- ITAppleEventTools.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index e4bd45a..217a1d1 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -19,6 +19,7 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev AppleEvent sendEvent, replyEvent; NSAppleEventDescriptor *send, *recv; + AEDesc nthDesc; AEBuildError buildError; OSStatus berr,err; @@ -37,7 +38,11 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev } err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL); - recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&replyEvent] autorelease]; + + err = AEGetNthDesc(&replyEvent, 1, typeWildCard, nil, &nthDesc); + if (!err) ITDebugLog(@"Error getting Nth desc."); + + recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&nthDesc] autorelease]; if (!err) [recv logDesc]; if (err) { -- 2.20.1 From 954eec6e4c0203f9836934550804f937a7e1ea91 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Sun, 25 Apr 2004 15:24:19 +0000 Subject: [PATCH 07/16] ITSendAEWithString returns the direct object AEDesc, or returns 0 if there is none. --- ITAppleEventTools.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index 217a1d1..9eaacb1 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -19,7 +19,9 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev AppleEvent sendEvent, replyEvent; NSAppleEventDescriptor *send, *recv; - AEDesc nthDesc; + AEDesc resultDesc; + DescType resultType; + Size resultSize; AEBuildError buildError; OSStatus berr,err; @@ -39,10 +41,14 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL); - err = AEGetNthDesc(&replyEvent, 1, typeWildCard, nil, &nthDesc); - if (!err) ITDebugLog(@"Error getting Nth desc."); + err = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize); + if (resultSize == 0 || err != 0) { + return nil; + } + + AEGetParamDesc(&replyEvent, keyDirectObject, resultType, &resultDesc); - recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&nthDesc] autorelease]; + recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc] autorelease]; if (!err) [recv logDesc]; if (err) { -- 2.20.1 From c40f5440e35326e867b0fa87ec9963d41205380c Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Mon, 17 May 2004 22:36:16 +0000 Subject: [PATCH 08/16] The ITLoginItem function(s) will easily set an app to autolaunch at login. --- ITLoginItem.h | 11 +++++++++++ ITLoginItem.m | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 ITLoginItem.h create mode 100755 ITLoginItem.m 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 -- 2.20.1 From 843b18fea32ec5481a9f64a4da67d11b00f4cf35 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Mon, 17 May 2004 23:06:45 +0000 Subject: [PATCH 09/16] The silly thing compiles now --- ITFoundation.xcode/project.pbxproj | 32 ++++++++++++++++++++++++++++++ ITLoginItem.h | 8 +++++--- ITLoginItem.m | 6 +++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index 89d2c80..17f83ae 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -81,6 +81,8 @@ }; 0867D691FE84028FC02AAC07 = { children = ( + 376AF4DD06597CA900F0979E, + 376AF4DE06597CA900F0979E, 08FB77AEFE84172EC02AAC07, 2AB93A2C057059DC007E748F, 32C88DFF0371C24200C91783, @@ -326,6 +328,34 @@ settings = { }; }; + 376AF4DD06597CA900F0979E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = ITLoginItem.h; + refType = 4; + sourceTree = ""; + }; + 376AF4DE06597CA900F0979E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = ITLoginItem.m; + refType = 4; + sourceTree = ""; + }; + 376AF4DF06597CA900F0979E = { + fileRef = 376AF4DD06597CA900F0979E; + isa = PBXBuildFile; + settings = { + }; + }; + 376AF4E006597CA900F0979E = { + fileRef = 376AF4DE06597CA900F0979E; + isa = PBXBuildFile; + settings = { + }; + }; 37B1C5160612592F00F99008 = { children = ( 370786C005C0B4D700E6D1BA, @@ -904,6 +934,7 @@ 3D97138A05D9FD6B0033607F, 37B1C5780612599000F99008, 37B1C57A0612599000F99008, + 376AF4DF06597CA900F0979E, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -945,6 +976,7 @@ 3D97138B05D9FD6B0033607F, 37B1C5770612599000F99008, 37B1C5790612599000F99008, + 376AF4E006597CA900F0979E, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; diff --git a/ITLoginItem.h b/ITLoginItem.h index 2bd02a8..ecb9daa 100755 --- a/ITLoginItem.h +++ b/ITLoginItem.h @@ -2,10 +2,12 @@ * ITLoginItem.h * ITFoundation * - * Created by Kent Sutherland on Sun May 16 2004. + * Created by Kent Sutherland on Mon May 17 2004. * Copyright (c) 2004 __MyCompanyName__. All rights reserved. * */ -#include -#include \ No newline at end of file +#import +#import +#import + diff --git a/ITLoginItem.m b/ITLoginItem.m index fe49255..ec2e582 100755 --- a/ITLoginItem.m +++ b/ITLoginItem.m @@ -1,8 +1,8 @@ /* - * ITLoginItem.c + * ITLoginItem.m * ITFoundation * - * Created by Kent Sutherland on Sun May 16 2004. + * Created by Kent Sutherland on Mon May 17 2004. * Copyright (c) 2004 __MyCompanyName__. All rights reserved. * */ @@ -25,7 +25,7 @@ BOOL ITSetLaunchApplicationOnLogin(NSString *path, BOOL flag) loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; //Create the alias data - FSMakeRefWithPath([path UTF8String], &fileRef); + FSPathMakeRef([path UTF8String], &fileRef, NULL); FSNewAlias(NULL, &fileRef, &alias); aliasData = [NSData dataWithBytes:&alias length:sizeof(alias)]; -- 2.20.1 From 7c82c90e68a68e77ea2b1162170b050134f2af46 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Mon, 17 May 2004 23:08:07 +0000 Subject: [PATCH 10/16] Adding ITLoginItem.h to ITFoundation.h --- ITFoundation.h | 1 + ITFoundation.xcode/project.pbxproj | 3 +++ 2 files changed, 4 insertions(+) diff --git a/ITFoundation.h b/ITFoundation.h index 83e4a16..6b8fced 100755 --- a/ITFoundation.h +++ b/ITFoundation.h @@ -18,6 +18,7 @@ #import #import #import +#import #import diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index 17f83ae..91308dd 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -348,6 +348,9 @@ fileRef = 376AF4DD06597CA900F0979E; isa = PBXBuildFile; settings = { + ATTRIBUTES = ( + Public, + ); }; }; 376AF4E006597CA900F0979E = { -- 2.20.1 From c7646de5dd9ea11811896be9505aee0564431ef8 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Tue, 18 May 2004 00:15:45 +0000 Subject: [PATCH 11/16] ITLoginItem functions work for the most part. The AliasData isn't completely correct yet though. --- ITLoginItem.h | 3 +++ ITLoginItem.m | 51 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/ITLoginItem.h b/ITLoginItem.h index ecb9daa..c145094 100755 --- a/ITLoginItem.h +++ b/ITLoginItem.h @@ -11,3 +11,6 @@ #import #import +//These functions check for a match with just the lastPathComponent, so it will handle people moving the app +void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag); +BOOL ITDoesApplicationLaunchOnLogin(NSString *path); \ No newline at end of file diff --git a/ITLoginItem.m b/ITLoginItem.m index ec2e582..f2f9e19 100755 --- a/ITLoginItem.m +++ b/ITLoginItem.m @@ -10,26 +10,33 @@ #import "ITLoginItem.h" #import "ITDebug.h" -BOOL ITSetLaunchApplicationOnLogin(NSString *path, BOOL flag) +void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) { + if ( (flag && ITDoesApplicationLaunchOnLogin(path)) || ![[NSFileManager defaultManager] fileExistsAtPath:path] ) { + return; + } NSUserDefaults *df = [NSUserDefaults standardUserDefaults]; NSMutableDictionary *loginwindow; NSMutableArray *loginarray; - FSRef fileRef; - AliasHandle alias; - NSData *aliasData; - ITDebugLog(@"Set if MenuPrefs launches at login to %i.", flag); + ITDebugLog(@"Set if \"%@\" launches at login to %i.", path, flag); [df synchronize]; loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy]; loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; - //Create the alias data - FSPathMakeRef([path UTF8String], &fileRef, NULL); - FSNewAlias(NULL, &fileRef, &alias); - aliasData = [NSData dataWithBytes:&alias length:sizeof(alias)]; - if (flag) { + FSRef fileRef; + AliasHandle alias; + NSData *aliasData; + FSPathMakeRef([path UTF8String], &fileRef, NULL); + FSNewAlias(NULL, &fileRef, &alias); + aliasData = [NSData dataWithBytes:&alias length:GetHandleSize((Handle)alias)]; + + if (!loginarray) { //If there is no loginarray of autolaunch items, create one + loginarray = [[[NSMutableArray alloc] init] autorelease]; + [loginwindow setObject:loginarray forKey:@"AutoLaunchedApplicationDictionary"]; + } + NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys: [[NSBundle mainBundle] bundlePath], @"Path", [NSNumber numberWithInt:0], @"Hide", @@ -39,7 +46,7 @@ BOOL ITSetLaunchApplicationOnLogin(NSString *path, BOOL flag) int i; for (i = 0; i < [loginarray count]; i++) { NSDictionary *tempDict = [loginarray objectAtIndex:i]; - if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]]) { [loginarray removeObjectAtIndex:i]; break; } @@ -48,5 +55,25 @@ BOOL ITSetLaunchApplicationOnLogin(NSString *path, BOOL flag) [df setPersistentDomain:loginwindow forName:@"loginwindow"]; [df synchronize]; [loginwindow release]; - return YES; +} + +BOOL ITDoesApplicationLaunchOnLogin(NSString *path) +{ + NSUserDefaults *df = [NSUserDefaults standardUserDefaults]; + NSDictionary *loginwindow; + NSMutableArray *loginarray; + NSEnumerator *loginEnum; + id anItem; + ITDebugLog(@"Checking if \"%@\" launches at login.", path); + [df synchronize]; + loginwindow = [df persistentDomainForName:@"loginwindow"]; + loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; + + loginEnum = [loginarray objectEnumerator]; + while ( (anItem = [loginEnum nextObject]) ) { + if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]] ) { + return YES; + } + } + return NO; } \ No newline at end of file -- 2.20.1 From 54439d22fae260328c4d4dc566de4e439c105c2d Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Tue, 18 May 2004 01:01:12 +0000 Subject: [PATCH 12/16] ITLoginItem for now. The AliasData doesn't work still. --- ITLoginItem.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ITLoginItem.m b/ITLoginItem.m index f2f9e19..636e2df 100755 --- a/ITLoginItem.m +++ b/ITLoginItem.m @@ -22,7 +22,7 @@ void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) ITDebugLog(@"Set if \"%@\" launches at login to %i.", path, flag); [df synchronize]; loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy]; - loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; + loginarray = [[loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"] mutableCopy]; if (flag) { FSRef fileRef; @@ -34,13 +34,11 @@ void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) if (!loginarray) { //If there is no loginarray of autolaunch items, create one loginarray = [[[NSMutableArray alloc] init] autorelease]; - [loginwindow setObject:loginarray forKey:@"AutoLaunchedApplicationDictionary"]; } - NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys: - [[NSBundle mainBundle] bundlePath], @"Path", - [NSNumber numberWithInt:0], @"Hide", - aliasData, @"AliasData", nil, nil]; + [[NSBundle mainBundle] bundlePath], @"Path", + [NSNumber numberWithInt:0], @"Hide", + aliasData, @"AliasData", nil, nil]; [loginarray addObject:itemDict]; } else { int i; @@ -52,9 +50,11 @@ void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) } } } + [loginwindow setObject:loginarray forKey:@"AutoLaunchedApplicationDictionary"]; [df setPersistentDomain:loginwindow forName:@"loginwindow"]; [df synchronize]; [loginwindow release]; + [loginarray release]; } BOOL ITDoesApplicationLaunchOnLogin(NSString *path) -- 2.20.1 From 82f3d7a2c51dd64ff663cdef7399d50cad4cca6b Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Sat, 22 May 2004 22:25:55 +0000 Subject: [PATCH 13/16] Commented out the aliasdata stuff that doesn't work --- ITFoundation.h | 6 +-- ITFoundation.xcode/project.pbxproj | 68 ------------------------------ ITLoginItem.m | 6 +-- 3 files changed, 6 insertions(+), 74 deletions(-) diff --git a/ITFoundation.h b/ITFoundation.h index 6b8fced..2edb3b2 100755 --- a/ITFoundation.h +++ b/ITFoundation.h @@ -14,8 +14,8 @@ #import -#import -#import +//#import +//#import #import #import #import @@ -25,4 +25,4 @@ #import #import -#import \ No newline at end of file +//#import \ No newline at end of file diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index 91308dd..21b6caa 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -313,21 +313,6 @@ refType = 4; sourceTree = ""; }; - 370786C205C0B4D700E6D1BA = { - fileRef = 370786C005C0B4D700E6D1BA; - isa = PBXBuildFile; - settings = { - ATTRIBUTES = ( - Public, - ); - }; - }; - 370786C305C0B4D700E6D1BA = { - fileRef = 370786C105C0B4D700E6D1BA; - isa = PBXBuildFile; - settings = { - }; - }; 376AF4DD06597CA900F0979E = { fileEncoding = 30; isa = PBXFileReference; @@ -483,36 +468,6 @@ refType = 4; sourceTree = ""; }; - 37B1C5770612599000F99008 = { - fileRef = 37B1C5730612599000F99008; - isa = PBXBuildFile; - settings = { - }; - }; - 37B1C5780612599000F99008 = { - fileRef = 37B1C5740612599000F99008; - isa = PBXBuildFile; - settings = { - ATTRIBUTES = ( - Public, - ); - }; - }; - 37B1C5790612599000F99008 = { - fileRef = 37B1C5750612599000F99008; - isa = PBXBuildFile; - settings = { - }; - }; - 37B1C57A0612599000F99008 = { - fileRef = 37B1C5760612599000F99008; - isa = PBXBuildFile; - settings = { - ATTRIBUTES = ( - Public, - ); - }; - }; 37B9B08005C1C47E00702FDB = { fileEncoding = 4; isa = PBXFileReference; @@ -529,21 +484,6 @@ refType = 4; sourceTree = ""; }; - 37B9B08205C1C47E00702FDB = { - fileRef = 37B9B08005C1C47E00702FDB; - isa = PBXBuildFile; - settings = { - ATTRIBUTES = ( - Public, - ); - }; - }; - 37B9B08305C1C47E00702FDB = { - fileRef = 37B9B08105C1C47E00702FDB; - isa = PBXBuildFile; - settings = { - }; - }; //370 //371 //372 @@ -924,8 +864,6 @@ 8DC2EF510486A6940098B216, 7CA50D7E054E7C600074E1D9, 7CA50B2D054E77950074E1D9, - 370786C205C0B4D700E6D1BA, - 37B9B08205C1C47E00702FDB, 7CA50B31054E77A00074E1D9, 3D2D8A13055E07D800F59C27, 2AB93A3205705A0C007E748F, @@ -935,8 +873,6 @@ 3D97137B05D9FB7C0033607F, 3D97137F05D9FBF40033607F, 3D97138A05D9FD6B0033607F, - 37B1C5780612599000F99008, - 37B1C57A0612599000F99008, 376AF4DF06597CA900F0979E, ); isa = PBXHeadersBuildPhase; @@ -972,13 +908,9 @@ 7CF6C931057D65B0007FEC13, 7CF6C939057D65BA007FEC13, 7C97DC2F05B614300013E85F, - 370786C305C0B4D700E6D1BA, - 37B9B08305C1C47E00702FDB, 3D97137C05D9FB7C0033607F, 3D97138105D9FBFA0033607F, 3D97138B05D9FD6B0033607F, - 37B1C5770612599000F99008, - 37B1C5790612599000F99008, 376AF4E006597CA900F0979E, ); isa = PBXSourcesBuildPhase; diff --git a/ITLoginItem.m b/ITLoginItem.m index 636e2df..05a16b0 100755 --- a/ITLoginItem.m +++ b/ITLoginItem.m @@ -25,12 +25,12 @@ void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) loginarray = [[loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"] mutableCopy]; if (flag) { - FSRef fileRef; + /*FSRef fileRef; AliasHandle alias; NSData *aliasData; FSPathMakeRef([path UTF8String], &fileRef, NULL); FSNewAlias(NULL, &fileRef, &alias); - aliasData = [NSData dataWithBytes:&alias length:GetHandleSize((Handle)alias)]; + aliasData = [NSData dataWithBytes:&alias length:GetHandleSize((Handle)alias)];*/ if (!loginarray) { //If there is no loginarray of autolaunch items, create one loginarray = [[[NSMutableArray alloc] init] autorelease]; @@ -38,7 +38,7 @@ void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys: [[NSBundle mainBundle] bundlePath], @"Path", [NSNumber numberWithInt:0], @"Hide", - aliasData, @"AliasData", nil, nil]; + [NSData data], @"AliasData", nil, nil]; [loginarray addObject:itemDict]; } else { int i; -- 2.20.1 From edec93e8881d5d2ee8ddcd0e1894f4538cbee8fd Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Mon, 24 May 2004 12:54:56 +0000 Subject: [PATCH 14/16] Small change to the project file --- ITFoundation.xcode/project.pbxproj | 13 +++++++++++-- ITLoginItem.h | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index 21b6caa..5c86eec 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -81,8 +81,6 @@ }; 0867D691FE84028FC02AAC07 = { children = ( - 376AF4DD06597CA900F0979E, - 376AF4DE06597CA900F0979E, 08FB77AEFE84172EC02AAC07, 2AB93A2C057059DC007E748F, 32C88DFF0371C24200C91783, @@ -157,6 +155,7 @@ 37B1C5280612596900F99008, 37B1C51F0612594A00F99008, 37B1C5190612593A00F99008, + 37138AB80661A243006A543D, 37B1C5160612592F00F99008, 37B1C5220612595500F99008, 37B1C5250612596000F99008, @@ -313,6 +312,16 @@ refType = 4; sourceTree = ""; }; + 37138AB80661A243006A543D = { + children = ( + 376AF4DD06597CA900F0979E, + 376AF4DE06597CA900F0979E, + ); + isa = PBXGroup; + name = ITLoginItem; + refType = 4; + sourceTree = ""; + }; 376AF4DD06597CA900F0979E = { fileEncoding = 30; isa = PBXFileReference; diff --git a/ITLoginItem.h b/ITLoginItem.h index c145094..277afb7 100755 --- a/ITLoginItem.h +++ b/ITLoginItem.h @@ -12,5 +12,5 @@ #import //These functions check for a match with just the lastPathComponent, so it will handle people moving the app -void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag); -BOOL ITDoesApplicationLaunchOnLogin(NSString *path); \ No newline at end of file +extern void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag); +extern BOOL ITDoesApplicationLaunchOnLogin(NSString *path); \ No newline at end of file -- 2.20.1 From 66f5b6df79892a68b1af28b6a1bfe7cf91f2cb56 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Sun, 25 Jul 2004 16:29:16 +0000 Subject: [PATCH 15/16] Added a new function to send an AE with a send string and a direct object AEDesc. --- ITAppleEventTools.h | 1 + ITAppleEventTools.m | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/ITAppleEventTools.h b/ITAppleEventTools.h index 5e41ab4..93b8be2 100755 --- a/ITAppleEventTools.h +++ b/ITAppleEventTools.h @@ -11,6 +11,7 @@ #import extern NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn); +NSAppleEventDescriptor *ITSendAEWithStringAndObject(NSString *sendString, const AEDesc *object, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn); extern NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn); extern NSAppleEventDescriptor *ITSendAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn); diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index 9eaacb1..e28f222 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -57,6 +57,53 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev return recv; } +NSAppleEventDescriptor *ITSendAEWithStringAndObject(NSString *sendString, const AEDesc *object, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn) +{ + //Add error checking... + pid_t pid; + + const char *usendString = [sendString UTF8String]; + + AppleEvent sendEvent, replyEvent; + NSAppleEventDescriptor *send, *recv; + AEDesc resultDesc; + DescType resultType; + Size resultSize; + + AEBuildError buildError; + OSStatus berr,err; + + if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) { + ITDebugLog(@"Error getting PID of application."); + return nil; + } + + berr = AEBuildAppleEvent(evClass, evID, typeProcessSerialNumber,psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, usendString); + send = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&sendEvent] autorelease]; + if (!berr) [send logDesc]; + + if (berr) { + ITDebugLog(@"Error: %d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[sendString substringToIndex:buildError.fErrorPos]); + } + err = AEPutParamDesc(&sendEvent, keyDirectObject, object); + err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL); + + err = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize); + if (resultSize == 0 || err != 0) { + return nil; + } + + AEGetParamDesc(&replyEvent, keyDirectObject, resultType, &resultDesc); + + recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc] autorelease]; + if (!err) [recv logDesc]; + + if (err) { + ITDebugLog(@"Send Error: %i",err); + } + return recv; +} + NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn) { return nil; -- 2.20.1 From 01ba0b1f650b7696b4507400d5ffb541323bf650 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Thu, 9 Sep 2004 21:14:34 +0000 Subject: [PATCH 16/16] Changed the timeout from none to default timeout. Updated to use 10.2.8 SDK. --- ITAppleEventTools.m | 4 ++-- ITFoundation.xcode/project.pbxproj | 15 ++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/ITAppleEventTools.m b/ITAppleEventTools.m index e28f222..7b897ee 100755 --- a/ITAppleEventTools.m +++ b/ITAppleEventTools.m @@ -39,7 +39,7 @@ NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode ev ITDebugLog(@"Error: %d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[sendString substringToIndex:buildError.fErrorPos]); } - err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL); + err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); err = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize); if (resultSize == 0 || err != 0) { @@ -86,7 +86,7 @@ NSAppleEventDescriptor *ITSendAEWithStringAndObject(NSString *sendString, const ITDebugLog(@"Error: %d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[sendString substringToIndex:buildError.fErrorPos]); } err = AEPutParamDesc(&sendEvent, keyDirectObject, object); - err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL); + err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); err = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize); if (resultSize == 0 || err != 0) { diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index 5c86eec..0ea001c 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -6,8 +6,6 @@ objectVersion = 39; objects = { 014CEA440018CDF011CA2923 = { - buildRules = ( - ); buildSettings = { COPY_PHASE_STRIP = NO; DEBUGGING_SYMBOLS = YES; @@ -22,8 +20,6 @@ name = Development; }; 014CEA450018CDF011CA2923 = { - buildRules = ( - ); buildSettings = { COPY_PHASE_STRIP = YES; GCC_ENABLE_FIX_AND_CONTINUE = NO; @@ -64,7 +60,7 @@ 0867D690FE84028FC02AAC07 = { buildSettings = { MACOSX_DEPLOYMENT_TARGET = 10.2; - SDKROOT = /Developer/SDKs/MacOSX10.2.7.sdk; + SDKROOT = /Developer/SDKs/MacOSX10.2.8.sdk; }; buildStyles = ( 014CEA440018CDF011CA2923, @@ -104,8 +100,7 @@ sourceTree = ""; }; 0867D69BFE84028FC02AAC07 = { - fallbackIsa = PBXFileReference; - isa = PBXFrameworkReference; + isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; @@ -113,8 +108,7 @@ sourceTree = ""; }; 0867D6A5FE840307C02AAC07 = { - fallbackIsa = PBXFileReference; - isa = PBXFrameworkReference; + isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; @@ -187,8 +181,7 @@ sourceTree = ""; }; 1058C7B1FEA5585E11CA2CBB = { - fallbackIsa = PBXFileReference; - isa = PBXFrameworkReference; + isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; -- 2.20.1