Scripting Additions Guide

CHAPTER 3
Writing Scripting Additions
Sample Scripting Addition 97
theErr = AEGetParamPtr(theAEEvent, keyDirectObject,
typeChar, &typeCode, (Ptr)&ourRezName,
sizeof(ourRezName), &actualSize);
if(theErr == noErr) {
/* 'C' string has a null as last char */
ourRezName[actualSize] = '\0';
/* convert to Pascal string */
c2pstr((char*) ourRezName);
/* now grab the 'snd ' resource by name*/
theSndHandle = GetNamedResource(kSndType,
(ConstStr255Param)ourRezName);
/* check the error */
theErr = ResError();
if(theErr == noErr)
theErr = PlaySound(theSndHandle); /*call our */
/* sound code*/
}
}
else {
if(typeCode == typeLongInteger) {
/*
If we get a typeLongInteger, the user wants us to
play a sound by its resource ID.
AppleScript will send us a long here and the
Resource Manager wants us to pass in a short, so
let's have the Apple Event Manager coerce it to a
short for us.
*/
theErr = AEGetParamPtr(theAEEvent, keyDirectObject,
typeShortInteger, &typeCode,
(Ptr)&ourRezID, sizeof(ourRezID),
&actualSize);