PDA

View Full Version : Apple Events


ClarustheDogCow
2002.06.07, 05:29 PM
I'm trying to make an apple event that simply sends the play command to iTunes, but this simple code wont work.
-snip-
#include <AppleEvents.h>
#include <Gestalt.h>
#include <stdio.h>

void main(void)
{
AppleEvent myevent,reply;
AEDesc mydesk;
OSType theSignature='hook';
OSErr myErr=noErr;
long aLong = 0;

if ((Gestalt(gestaltAppleEventsAttr, &aLong) == noErr)==true){
if (myErr==noErr)
myErr=AECreateDesc(typeApplSignature,(Ptr)&theSignature,sizeof(theSignature),&mydesk);

if (myErr==noErr)
{
myErr=AECreateAppleEvent('APPL','Play',&mydesk,kAutoGenerateReturnID,kAnyTransactionID,&myevent);
}

if (myErr==noErr)
{
myErr=AESend(&myevent,&reply,kAENoReply+kAEAlwaysInteract+kAECanSwitchLay er,kAENormalPriority,kAEDefaultTimeout,nil,nil);
AEDisposeDesc(&reply);
AEDisposeDesc(&mydesk);
AEDisposeDesc(&myevent);
}
printf("%d",myErr);
}
}

RedWolf
2002.06.07, 10:53 PM
Do you have a SIZE resource with the "High level event aware" bit set?

Page 6-61 of IM: Volume VI says:

"If you want to send Apple events, your application must also handle the required Apple events."

ClarustheDogCow
2002.06.08, 06:52 AM
Yes its on. I dont have a clue why it isn't working. Thats probably why I posted here=]

RedWolf
2002.06.08, 11:55 AM
What's the result code from AESend? Your code segment does not show you checking it (or from any of the AE calls).

ClarustheDogCow
2002.06.08, 02:41 PM
I was going to keep it simple, but I edited my post and that is word for word what my code looks like. I get 0 as my error return value, and I have checked to make sure that each call has been sent.

RedWolf
2002.06.08, 08:06 PM
What version of iTunes are you running? I opened the dictionary for iTunes 1.1 and it only supports the required suite.

ClarustheDogCow
2002.06.09, 09:38 AM
iTunes 2, which has improved scripting abilities. I've wrote an applescript that does the same thing, but it works.
Is their any guide to converting applescript events to apple events? I'm using resorcerer and it says that the name is play, reply type null, class hook, and ID Play. It also says that the "Internal code (DoAppleEvent refCon value)" is 20000, if that matters.

ClarustheDogCow
2002.06.10, 08:36 AM
Sheesh, I found my problem. I was sending the file type instead of the Event Class. What was I thinking? (Or rather, why wasnt I?)