Skip navigation.
 
mlRe: Quit iTunes
FROM : has
DATE : Sat May 24 21:38:02 2008

Mr. Gecko wrote:

>>> How would I quit iTunes. There is a way to launch it with
>>> NSWorkspace but how about quit?
>>>

>>
>>
>> Send a quit AppleEvent

>
> How would I do that?
> I have been looking for a while and I found aevtquit but I can't find
> out how to send.


Example:

#include <Carbon/Carbon.h>

OSStatus QuitApplication(char *bundleID) {
    AppleEvent evt, res;
    OSStatus err;

    err = AEBuildAppleEvent(kCoreEventClass, kAEQuitApplication,
                            typeApplicationBundleID,
                            bundleID, strlen(bundleID),
                            kAutoGenerateReturnID,
                            kAnyTransactionID,
                            &evt, NULL, "");
    if (err == noErr) {
        err = AESendMessage(&evt, &res, kAENoReply, kAEDefaultTimeout);
        AEDisposeDesc(&evt);
    }
    return err;
}

int main (int argc, const char * argv[]) {
    return QuitApplication("com.apple.itunes");
}


For anything more complex, use a high-level bridge (e.g. see my sig).

HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

Related mailsAuthorDate
mlQuit iTunes Mr. Gecko May 24, 17:49
mlRe: Quit iTunes Tommy Nordgren May 24, 18:13
mlRe: Quit iTunes Mr. Gecko May 24, 18:33
mlRe: Quit iTunes I. Savant May 24, 18:43
mlRe: Quit iTunes Tommy Nordgren May 24, 21:23
mlRe: Quit iTunes has May 24, 21:38
mlRe: Quit iTunes Mr. Gecko May 24, 21:43
mlRe: Quit iTunes Mr. Gecko May 24, 21:53
mlRe: Re: Quit iTunes Daniel Dickison May 24, 22:53
mlRe: Quit iTunes Gregory Weston May 25, 01:45
mlRe: Quit iTunes Uli Kusterer May 26, 00:26