Quit iTunes

  • How would I quit iTunes. There is a way to launch it with NSWorkspace
    but how about quit?
  • On 24 maj 2008, at 17.49, 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
    ------------------------------------------------------
    "Home is not where you are born, but where your heart finds peace" -
    Tommy Nordgren, "The dying old crone"
    <tommy.nordgren...>
  • 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.
    On May 24, 2008, at 11:13 AM, Tommy Nordgren wrote:

    >
    > On 24 maj 2008, at 17.49, 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
    > ------------------------------------------------------
    > "Home is not where you are born, but where your heart finds peace" -
    > Tommy Nordgren, "The dying old crone"
    > <tommy.nordgren...>
    >
    >
  • On May 24, 2008, at 12:33 PM, Mr. Gecko wrote:

    > 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.

      Read the documentation:

    http://developer.apple.com/documentation/AppleScript/Conceptual/AppleEvents
    /intro_aepg/chapter_1_section_1.html


      Oddly enough, there's a section called, "Creating & Sending Apple
    Events" that has some code examples ...

    --
    I.S.
  • On 24 maj 2008, at 18.33, Mr. Gecko wrote:

    > How would I do that?

    NSAppleScript * script = [[[NSAppleScript alloc]
    initWithSource:@"tell application \"iTunes\" \n quit \nend tell"]
    autoRelease];
    [script executeAndReturnError: nil];

    >
    > I have been looking for a while and I found aevtquit but I can't
    > find out how to send.
    > On May 24, 2008, at 11:13 AM, Tommy Nordgren wrote:
    >
    >>
    >> On 24 maj 2008, at 17.49, 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
    >> ------------------------------------------------------
    >> "Home is not where you are born, but where your heart finds peace" -
    >> Tommy Nordgren, "The dying old crone"
    >> <tommy.nordgren...>
    >>
    >>


    ----------------------------------
    Skinheads are so tired of immigration, that they are going to move to
    a country that don't accept immigrants!
    Tommy Nordgren
    <tommy.nordgren...>
  • 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
  • That is slow because it has to compile. but if I can't get this apple
    event to work than I might do that
    On May 24, 2008, at 2:23 PM, Tommy Nordgren wrote:

    >
    > On 24 maj 2008, at 18.33, Mr. Gecko wrote:
    >
    >> How would I do that?
    >
    > NSAppleScript * script = [[[NSAppleScript alloc]
    > initWithSource:@"tell application \"iTunes\" \n quit \nend tell"]
    > autoRelease];
    > [script executeAndReturnError: nil];
    >
    >
    >>
    >> I have been looking for a while and I found aevtquit but I can't
    >> find out how to send.
    >> On May 24, 2008, at 11:13 AM, Tommy Nordgren wrote:
    >>
    >>>
    >>> On 24 maj 2008, at 17.49, 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
    >>> ------------------------------------------------------
    >>> "Home is not where you are born, but where your heart finds peace" -
    >>> Tommy Nordgren, "The dying old crone"
    >>> <tommy.nordgren...>
    >>>
    >>>

    >
    > ----------------------------------
    > Skinheads are so tired of immigration, that they are going to move
    > to a country that don't accept immigrants!
    > Tommy Nordgren
    > <tommy.nordgren...>
    >
    >
    >
  • Thank you so much it works.
    On May 24, 2008, at 2:38 PM, has wrote:

    > 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
    >
  • >> NSAppleScript * script = [[[NSAppleScript alloc]
    >> initWithSource:@"tell application \"iTunes\" \n quit \nend tell"]
    >> autoRelease];
    >> [script executeAndReturnError: nil];
    >
    > That is slow because it has to compile. but if I can't get this
    > apple event to work than I might do that

    I would hope that the frequency with which you tell iTunes to quit is
    low enough that the overhead of compiling the script would be
    negligible :)
  • Mr. Gecko wrote:

    > That is slow because it has to compile. but if I can't get this apple
    > event to work than I might do that

    It's not Cocoa, but it is efficient...

    To find out if an app with a given bundle ID is running:

    #include "ProcessIsRunningWithBundleID.h"
    #include <IOKit/IOCFBundle.h>

    int ProcessIsRunningWithBundleID(CFStringRef inBundleID,
    ProcessSerialNumber* outPSN)
    {
      int theResult = 0;

      ProcessSerialNumber thePSN = {0, kNoProcess};
      OSErr theError = noErr;
      do {
        theError = GetNextProcess(&thePSN);
        if(theError == noErr)
        {
          CFDictionaryRef theInfo = NULL;
          theInfo = ProcessInformationCopyDictionary(&thePSN,

    kProcessDictionaryIncludeAllInformationMask);
          if(theInfo)
          {
            CFStringRef theBundleID = CFDictionaryGetValue(theInfo,
    IOBundleIdentifierKey);
            if(theBundleID)
            {
              if(CFStringCompare(theBundleID, inBundleID, 0) ==
    kCFCompareEqualTo)
              {
                theResult = 1;
              }
            }
            CFRelease(theInfo);
          }
        }
      } while((theError != procNotFound) && (theResult == 0));

      if(theResult && outPSN)
      {
        *outPSN = thePSN;
      }

      return theResult;
    }

    The second argument can be NULL. If you pass the address of a
    ProcessSerialNumber, you can then use this routine to quit it.

    OSErr QuitApplicationByPSN(const ProcessSerialNumber* inPSN)
    {
      AppleEvent theQuitEvent = {typeNull, NULL};
      AEBuildError theBuildError;
      OSErr theError = AEBuildAppleEvent(kCoreEventClass,
    kAEQuitApplication, typeProcessSerialNumber, inPSN,
        sizeof(ProcessSerialNumber), kAutoGenerateReturnID,
    kAnyTransactionID, &theQuitEvent,
        &theBuildError,"");
      if(theError == noErr)
      {
        AppleEvent theReply = {};
        theError = AESend(&theQuitEvent, &theReply, kAENoReply |
    kAENeverInteract,
          kAENormalPriority, kNoTimeOut, NULL, NULL);
        (void)AEDisposeDesc(&theQuitEvent);
      }
      return theError;
    }
  • Am 24.05.2008 um 17:49 schrieb Mr. Gecko:
    > How would I quit iTunes. There is a way to launch it with
    > NSWorkspace but how about quit?

      You could use the scripting bridge.

    Cheers,
    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
    http://www.zathras.de
previous month may 2008 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Go to today