Using AEBuild commands to send IM to iChat and AIM
Using AEBuild commands to send IM to iChat and AIM
- Subject: Using AEBuild commands to send IM to iChat and AIM
- From: Steve Sheets <email@hidden>
- Date: Thu, 25 Nov 2004 01:33:59 -0500
Happy thanksgiving...
To help celebrate, and give back to this community, here are two procedures that use AEBuild command to automate sending Instant Messages (IMs) to iChat or AIM (America Online Instant Messenger). I was originally using
NSAppleScript to run Applescripts that I create on the fly to do this, but using
AEBuildAppleEvent is better. Note that the old code is still in the procedures, but commented out (I include it for reference). I highly recommend Script Debugger 3.0 from Late Night software, if you are trying to create AEBuild commands. It has a log window that displays any script as it runs in AEBuild format.
Sincerely,
Steve Sheets
Midnight Mage Software
email@hidden
ps. I hope to extend these command for Yahoo, Mail and other applications, as well as start sending Rich Text Format (RTF) and HTML, but have not done this yet.
-------------
// Send Text Message to AIM (given account name and message)
void G_SendIM_AIM(NSString* p_who,
NSString* p_message)
{
// Make sure parameters are valid
if (p_who && p_message) {
if (([p_who length]>0) && ([p_message length]>0)) {
// New method using AEBuild
AppleEvent a_event;
AppleEvent p_reply;
OSErr a_err;
OSType adrFinder = 'AimC';
// Create AE
a_err = AEBuildAppleEvent('im ', 'send',
typeApplSignature, &adrFinder,sizeof(adrFinder),
kAutoGenerateReturnID, kAnyTransactionID, &a_event, NULL,
"'to ':TEXT(@),'----':TEXT(@)",
[p_who UTF8String], [p_message UTF8String]);
if (a_err != noErr)
return;
// Send Created AE
a_err = AESend(&a_event, &p_reply, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
AEDisposeDesc(&a_event);
AEDisposeDesc(&p_reply);
/* Old method
// String for script
NSString* a_string = [NSString stringWithFormat:@"tell application \"AOL Instant Messenger (SM)\" \n if online then \n send \"%@\" to \"%@\" \n end if \n end tell \n", p_message, p_who];
if (a_string) {
NSAppleScript *a_script;
// create script
a_script = [[NSAppleScript alloc] initWithSource:a_string];
if (a_script) {
// Excute script
[a_script executeAndReturnError:nil];
[a_script release];
}
}
*/
}
}
}
// Send Text Message to iChat (given account name and message)
void G_SendIM_iChat(NSString* p_who,
NSString* p_message)
{
if (p_who && p_message) {
if (([p_who length]>0) && ([p_message length]>0)) {
// New method using AEBuild
AppleEvent a_event;
AppleEvent p_reply;
OSErr a_err;
OSType adrFinder = 'fez!';
// Create AE
a_err = AEBuildAppleEvent('icht', 'send',
typeApplSignature, &adrFinder,sizeof(adrFinder),
kAutoGenerateReturnID, kAnyTransactionID, &a_event, nil,
"'TO ':obj{'form':'name','want':'pres','seld':TEXT(@),'from':obj{form:'indx',want:'icsv',seld:1,from:'null'()}},'----':TEXT(@)",
[p_who UTF8String], [p_message UTF8String]);
if (a_err != noErr)
return;
// Send Created AE
a_err = AESend(&a_event, &p_reply, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
AEDisposeDesc(&a_event);
AEDisposeDesc(&p_reply);
/* Old method - not used anymore
// String for script
NSString* a_string = [NSString stringWithFormat:@"tell application \"iChat\" \n send \"%@\" to account \"%@\" of service 1 \n end tell \n", p_message, p_who];
if (a_string) {
NSAppleScript *a_script;
// create script
a_script = [[NSAppleScript alloc] initWithSource:a_string];
if (a_script) {
// Excute script
[a_script executeAndReturnError:nil];
[a_script release];
}
}
*/
}
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden