How to close an active application??

Discussion in 'Mac Programming' started by Sergio10, Oct 3, 2007.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hello developers!

    How to close an active application using Mac API(for example QuickTime player) I develop on C/C++, Mac OS X 10.4.8
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    If it has to be C or C++ then you will have to send and AppleEvent to the application in question. This is not all that simple to achieve. It's easier to use AppleScript:

    tell application "name" to quit

    If you were using Objective C/Cocoa then you could use NSAppleScript.

    If it has to be C/C++ then you are probably stuck with the complex and ugly Apple Event Manager

    Note that if you are in C it might be easier to shell out and use osascript -e 'tell application "name" to quit' than to use the Event Manager...
     
  3. Sergio10 thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #3
    Robbieduncan, is it possible using AppleScript to catch events from application. For example: If user opens QuickTime player and begin to preroll movie I must know what he do now. Is it possible with AppleScript?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Unless the application chooses to send an event then no, there is no automatic way to know when a specific event happens in another app that I know of.
     
  5. MongoTheGeek macrumors 68040

    MongoTheGeek

    Joined:
    Sep 13, 2003
    Location:
    Its not so much where you are as when you are.
    #5
    AppleScript can be recorded off of some applications. Implementing it has always been a pain and with a bunch of changes to make adding scriptability easy, nothing really has been done to make recordability easy.

    On possible option is that quicktime movies can trigger actions, but that means you need control over the movie.

    You may want to make your own movie player if that is all you looking for. Its fairly easy to do with cocoa and interface builder. Then you can key off of the movie player itself.
     
  6. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #6
    POSIX signals?

    What about sending the process a simple SIGTERM, or if it doesn't need to do any specific cleanup a SIGKILL, i.e.

    kill (<pid of receiving process>, 15) //SIGTERM

    kill ( <pid of receiving process>, 9); //SIGKILL
     

Share This Page