Solved

Quiting another app with an Apple Event

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

919 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

19 Experts available now in Live!

Get 1:1 Help Now