Solved

Quiting another app with an Apple Event

Posted on 2000-04-13
2
241 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 100 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now