jens@0: // jens@0: // IChatUtils.m jens@0: // MYUtilities jens@0: // jens@0: // Created by Jens Alfke on 3/3/08. jens@0: // Copyright 2008 Jens Alfke. All rights reserved. jens@0: // jens@0: jens@0: #import "IChatUtils.h" jens@0: #import "iChatBridge.h" jens@0: jens@0: @implementation IChatUtils jens@0: jens@0: jens@0: static iChatApplication *sIChatApp; jens@0: jens@0: + (void) initialize jens@0: { jens@0: if( ! sIChatApp ) { jens@0: sIChatApp = [SBApplication applicationWithBundleIdentifier: @"com.apple.iChat"]; jens@0: sIChatApp.timeout = 5*60; // in ticks jens@0: } jens@0: } jens@0: jens@0: jens@0: + (SBApplication*) app {return sIChatApp;} jens@0: + (BOOL) isRunning {return sIChatApp.isRunning;} jens@0: + (void) activate {[sIChatApp activate];} jens@0: jens@0: jens@0: + (iChatTextChat*) activeChat jens@0: { jens@0: if( ! [sIChatApp isRunning] ) jens@0: return nil; jens@0: SBElementArray *chats = sIChatApp.textChats; jens@0: if( chats.count==0 ) jens@0: return nil; jens@0: iChatTextChat *chat = [chats objectAtIndex: 0]; jens@0: if( ! chat.active ) jens@0: return nil; jens@0: return chat; jens@0: } jens@0: jens@0: + (NSString*) activeChatPartner jens@0: { jens@0: iChatTextChat *chat = [self activeChat]; jens@0: if( ! chat ) jens@0: return nil; jens@0: NSMutableArray *names = $marray(); jens@0: for( iChatBuddy *b in [chat participants] ) jens@0: [names addObject: (b.fullName ?: b.name)]; jens@0: return [names componentsJoinedByString: @", "]; jens@0: } jens@0: jens@0: + (BOOL) sendMessage: (NSString*)msg jens@0: { jens@0: iChatTextChat *chat = [self activeChat]; jens@0: if( ! chat ) jens@0: return NO; jens@0: [sIChatApp send: msg to: chat]; jens@0: return YES; jens@0: } jens@0: jens@0: jens@0: @end