Re: Can I Send Apple Events in Cocoa?
Re: Can I Send Apple Events in Cocoa?
- Subject: Re: Can I Send Apple Events in Cocoa?
- From: Kaydell Leavitt <email@hidden>
- Date: Sun, 11 Dec 2005 12:02:15 -0800 (PST)
Hi,
Can I call the following Carbon C++ function from the
app that is thusfar written in Cocoa and Objective C?
I have to use Apple Events because that's what's
available to me.
Thanks.
Kaydell
OSStatus SendRoutineMaintenanceAE(FSSpec fileSpec) {
// --- declare local variables --- //
OSStatus status;
AppleEvent theAEvent, theReply;
AEAddressDesc inventoryAddress;
OSType inventoryCreator = kInventorySignature;
long index;
// --- set up locals --- //
AECreateDesc(typeNull, NULL, 0, &theAEvent);
AECreateDesc(typeNull, NULL, 0, &inventoryAddress);
AECreateDesc(typeNull, NULL, 0, &theReply);
// --- create an Do Routine Web Maint. event
targeting the Inventory Client app --- //
status = AECreateDesc(typeApplSignature,
&inventoryCreator, sizeof(inventoryCreator),
&inventoryAddress);
if (noErr == status)
status = AECreateAppleEvent(kInventoryAnalyzerClass,
kRoutineWebMaintenance, &inventoryAddress,
kAutoGenerateReturnID, kAnyTransactionID, &theAEvent);
// --- send the event to the POSIM Inventory Client
--- //
if (noErr == status)
status = AESend(&theAEvent, &theReply, kAEWaitReply,
kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
// --- clean up and leave --- //
AEDisposeDesc(&theAEvent);
AEDisposeDesc(&inventoryAddress);
AEDisposeDesc(&theReply);
// --- return the status --- //
return status;
}
--- Bill Cheeseman <email@hidden> wrote:
>
on 2005-12-10 12:07 AM, Kaydell Leavitt at
>
email@hidden wrote:
>
>
> I need to send an Apple Event to a program to
>
automate
>
> exporting of data from it to a web-site.
>
>
>
> As far as I can tell, I can receive Apple Events
>
in
>
> Cocoa, but I can't send them directly.
>
>
Cocoa doesn't have its own facility to send Apple
>
events, but it's easy
>
enough to use AESendMessage once you've built up the
>
Apple event. You can
>
built up the Apple event using the appropriate Cocoa
>
classes.
>
>
There are many ways to do messaging in Mac OS X, and
>
Apple events certainly
>
have their place. This is especially true when you
>
want to control or read
>
another application that is AppleScriptable, and
>
when you want to send one
>
of the core Apple events to which all applications
>
respond, such as 'quit'.
>
Here's how I send a 'quit' Apple event to my helper
>
application, using Cocoa
>
as much as I can:
>
>
- (void)stopUIActions {
>
if ([self isUIActionsRunning]) {
>
OSType signature = 'UIAc';
>
NSAppleEventDescriptor *applicationDesc =
>
[NSAppleEventDescriptor
>
descriptorWithDescriptorType:typeApplSignature
>
bytes:&signature
>
length:sizeof(OSType)];
>
NSAppleEventDescriptor
>
*quitApplicationAppleEvent =
>
[NSAppleEventDescriptor
>
appleEventWithEventClass:kCoreEventClass
>
eventID:kAEQuitApplication
>
targetDescriptor:applicationDesc
>
returnID:kAutoGenerateReturnID
>
transactionID:kAnyTransactionID];
>
AppleEvent *quitApplicationAppleEventPtr =
>
(AEDesc
>
*)[quitApplicationAppleEvent aeDesc];
>
if (quitApplicationAppleEventPtr) {
>
>
AESendMessage(quitApplicationAppleEventPtr, NULL,
>
kAENoReply,
>
kAEDefaultTimeout);
>
}
>
}
>
}
>
>
>
--
>
>
Bill Cheeseman - email@hidden
>
Quechee Software, Quechee, Vermont, USA
>
http://www.quecheesoftware.com
>
>
PreFab Software -
>
http://www.prefab.com/scripting.html
>
The AppleScript Sourcebook -
>
http://www.AppleScriptSourcebook.com
>
Vermont Recipes -
>
http://www.stepwise.com/Articles/VermontRecipes
>
>
>
_______________________________________________
>
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
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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