Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Quiting another app with an Apple Event

Posted on 2000-04-13
2
Medium Priority
?
270 Views
Last Modified: 2013-12-26
How would I tell another application  to quit using an Apple Event. I have found that the program is running using FindAProcess(). How would I code this. I tried messing with other AE code that I have but it doesn't work.
0
Comment
Question by:dwp090598
2 Comments
 
LVL 2

Accepted Solution

by:
munsie earned 400 total points
ID: 2717579
this code is from just_finder.c on the apple sample code website (www.apple.com/developer  look for a sample code link on the sidebar)

this is the part that should do what you want.  The original code didn't do any of this until WaitNextEvent() returned a null event.  You may or may not, depending on your program.

it's assumed that you already have the correct headers you need, and so forth.

--------

OSErr myErr = AECreateDesc(typeProcessSerialNumber, (Ptr)&theProcess, sizeof(theProcess), &ourPSNDesc);
if (myErr == noErr)
{
                        
// Create the 'quit' Apple event for this process.  This might return error
// -603 for desk accessories if you don't call WaitNextEvent enough times
// like above.
                        
myErr = AECreateAppleEvent(kCoreEventClass,kAEQuitApplication, &ourPSNDesc, kAutoGenerateReturnID, kAnyTransactionID, &ourQuitEvent);
if (myErr == noErr)
{
// send the event
myErr = AESend(&ourQuitEvent, &ourReplyEvent, kAENoReply, kAENormalPriority, kNoTimeOut, 0L, 0L);
if (myErr == noErr)
{
// Sadly, some applications won't respond to Apple events and do
// what they're supposed to do until they're brought to the front,
// so we do that, and continue our work in the background.

SetFrontProcess(&theProcess);
}

// dispose of the event only if we succesfully created it.
myErr = AEDisposeDesc(&ourQuitEvent);
}
                        
// dispose of the descriptor only if we succesfully created it.
myErr = AEDisposeDesc(&ourPSNDesc);
}

------

good luck,
dennis
0
 

Author Comment

by:dwp090598
ID: 2720234
Worked perfect.

THank You
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question