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 23:19:22 -0800 (PST)
Hi,
I saw some Cocoa code in the project that I'm working
on that was written by my predecessor. He used
embeded Apple Script in the Cocoa/Objective-C app that
I'm working on. I thought that this was not good,
that I could do better writing code in C, but so far,
I've only been able to assume that the database server
and the inventory client app are both running. It's
not likely that there will be two Inventory clients
running, but it can happen. I want to be able to
specify which instance of the Inventory Client gets
the Apple Event if more than one is running.
The following Apple Script is really what I need, but
with the additional ability to specify an app if two
or more copies are running.
tell application "Inventory Client"
activate
«event InvARTMT»
end tell
Kaydell
--- Kaydell Leavitt <email@hidden> wrote:
>
Thanks.
>
>
This is what I have so far. It works in Carbon. I
>
haven't tried calling it from Cocoa yet. It works
>
when I use the application signature, but I was
>
hoping
>
to be able to specify the app to get the Apple Event
>
with a relative path from my app.
>
>
Using the address of the application signature
>
works,
>
but a FSSpec and an FSRef both fail with a -600
>
error.
>
I read something in mach ports and such. It sounds
>
to me like I'm running into something that changed
>
with OS X, where things now are in Unix and the
>
low-level mechanism for sending Apple Events has
>
changed from the PPC toolbox to a Unix thing.
>
>
Kaydell
>
>
OSStatus SendRoutineMaintenanceAE(FSRef appRef) {
>
// --- declare local variables --- //
>
OSStatus status;
>
AppleEvent theAEvent, theReply;
>
AEAddressDesc inventoryAddress;
>
// OSType inventoryCreator = kInventorySignature;
>
// --- set up locals --- //
>
AECreateDesc(typeNull, NULL, 0, &theAEvent);
>
AECreateDesc(typeNull, NULL, 0, &inventoryAddress);
>
AECreateDesc(typeNull, NULL, 0, &theReply);
>
// --- create an open documents event targeting the
>
finder --- //
>
// status = AECreateDesc(typeApplSignature,
>
&inventoryCreator, sizeof(inventoryCreator),
>
&inventoryAddress);
>
status = AECreateDesc(typeFSRef, &appRef,
>
sizeof(appRef), &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;
>
}
>
>
--- Daniel Jalkut <email@hidden> wrote:
>
>
> Ricky is right - it's generally safe to assume
>
that
>
> you can "use what
>
> you want" when it comes to incorporating non-Cocoa
>
> stuff into your
>
> application.
>
>
>
> The fact that the inquiry is about events makes it
>
> slightly less of a
>
> "slam dunk" piece of advice, because there are
>
some
>
> areas in which a
>
> Cocoa application is seriously limited from
>
> participating in the
>
> "Carbon Event" model, but when it comes to
>
> *AppleEvents* in
>
> particular, there shouldn't be any restrictions.
>
>
>
> Daniel
>
>
>
> On Dec 11, 2005, at 3:37 PM, Ricky Sharp wrote:
>
>
>
> > This is all just C, so drop it in as-is to your
>
> existing codebase
>
> > and just call it. Remember that Obj-C is a
>
> superset of C. Also
>
> > remember to link against the Carbon framework to
>
> gain access to
>
> > those APIs.
>
> >
>
> > Note that you can also incorporate C++ code;
>
> search the docs/
>
> > archives for examples if needed.
>
>
>
>
>
>
>
__________________________________________________
>
Do You Yahoo!?
>
Tired of spam? Yahoo! Mail has the best spam
>
protection around
>
http://mail.yahoo.com
>
__________________________________________________
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