Professional Web Applications Themes

AppleMail and AppleEvents - Mac Programming

I'm trying to talk to AppleMail with AppleEvents. Just as a test I'm trying to use the kAEQuitApplication event with AppleMail. I'm attaching this apple event to a LaunchAppplication() parameter. AppleMail is opening but not quitting. Has anyone else had any experience with using AppleEvents, AppleMail, and LaunchApplications() together that could give me some advice? Also, I need to find "Event ID's" that I can use with AppleMail to open a new mail, add to:, subject, title, and add attachment. Where could I find a list of them? Below is a snippet of my code. Your help would be greatly ...

  1. #1

    Default AppleMail and AppleEvents

    I'm trying to talk to AppleMail with AppleEvents.

    Just as a test I'm trying to use the kAEQuitApplication event with
    AppleMail. I'm attaching this apple event to a LaunchAppplication()
    parameter. AppleMail is opening but not quitting.

    Has anyone else had any experience with using AppleEvents, AppleMail,
    and LaunchApplications() together that could give me some advice?

    Also, I need to find "Event ID's" that I can use with AppleMail to
    open a new mail, add to:, subject, title, and add attachment. Where
    could I find a list of them?

    Below is a snippet of my code. Your help would be greatly appreciated!

    //create a desc for the target app
    OSType appSignature = 'emal';
    err = AECreateDesc( typeProcessSerialNumber, &psn, sizeof( psn ),
    &targetDesc );

    //create apple event
    err = AECreateAppleEvent( kCoreEventClass, kAEOpenDoents,
    &targetDesc, kAutoGenerateReturnID, kAnyTransactionID, &event );

    //Find Mail application
    err = LSGetApplicationForInfo(kLSUnknownType,'emal', nil, kLSRolesAll,
    &outAppRef, &outAppURL);

    // Make FSSpec
    err = FSRefMakeFSSpec( &outAppRef, &getFSSpec) ;

    // Add AppleEvent to parameter
    err = AECoerceDesc( &event, typeAppParameters, &launchParam ) ;

    HLock( (Handle)launchParam.dataHandle ) ;
    launchMailapp.launchAppParameters =
    (AppParametersPtr)*launchParam.dataHandle ;
    HUnlock( (Handle)launchParam.dataHandle ) ;

    launchMailapp.launchAppSpec = &getFSSpec ;
    launchMailapp.launchBlockID = extendedBlock ;
    launchMailapp.launchEPBLength = extendedBlockLen ;
    launchMailapp.launchFileFlags = 0 ;
    //launchMailapp.launchControlFlags = launchContinue |
    launchNoFileFlags | launchUseMinimum ;

    err = LaunchApplication( &launchMailapp) ;
    V.Vill Guest

  2. #2

    Default Re: AppleMail and AppleEvents

    V.Vill <com> wrote:
     

    Class codes are in Mail/Contents/Resources/Message.scriptSuite. Event
    codes are the normal codes for get, set, etc. If you don't know the
    codes for those, you're playing the wrong game! :) Why not save yourself
    some trouble and write all this in AppleScript? Hmm. Sorry about the
    apparent conflict of interest; that wasn't intended the way it sounded.
    m.


    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    AppleScript: The Definitive Guide
    http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  3. #3

    Default Re: AppleMail and AppleEvents

    >Event codes are the normal codes for get, set, etc. If you don't know the 

    Thanks for the info!

    Actually, I'm new to this stuff so any help would be appreciated.
    Could you point me to some doentation for using normal codes
    like get, set, etc in AppleEvents (even better, some examples).

    I know how they appear in AppleScripts but how do they appear/work in
    AppleEvents?

    Thanks!


    com (matt neuburg) wrote in message news:<1g63vwj.mmpt3n392f28N%com>... 
    >
    > Class codes are in Mail/Contents/Resources/Message.scriptSuite. Event
    > codes are the normal codes for get, set, etc. If you don't know the
    > codes for those, you're playing the wrong game! :) Why not save yourself
    > some trouble and write all this in AppleScript? Hmm. Sorry about the
    > apparent conflict of interest; that wasn't intended the way it sounded.
    > m.[/ref]
    V.Vill Guest

  4. #4

    Default Re: AppleMail and AppleEvents

    V.Vill <com> wrote:
     
    >
    > Thanks for the info!
    >
    > Actually, I'm new to this stuff so any help would be appreciated.
    > Could you point me to some doentation for using normal codes
    > like get, set, etc in AppleEvents (even better, some examples).
    >
    > I know how they appear in AppleScripts but how do they appear/work in
    > AppleEvents?[/ref]

    Well, easiest way to learn is to watch them. In other words, say
    whatever you want to say as an AppleScript command and watch the
    resulting Apple events fly through the system. My book has examples of
    how to do this using setenv AEDebug 1 and so forth (some guy has also
    just put up an app on VersionTracker that does this for you), plus I
    recommend you use Script Debugger which costs $ but does show you this
    stuff very easily. m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    AppleScript: The Definitive Guide
    http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  5. #5

    Default Re: AppleMail and AppleEvents

    In article <google.com>,
    com (V.Vill) wrote:
     

    1.) You don't send the Quit in the Launch. If your GetNextProcess()
    GetProcessInfo loop shows that the process is running, you use AESend()
    to send it events.

    2.) kAEOpenDoents is defined to take an AEList of file specifiers,
    but in OS X, FSSpecs aren't meaningful is sent from one process to
    another. You need to put an AEList of AEDescriptors of AliasHandles as
    the direct object parameter of the appleEvent that you are coercing to a
    typeAppParameters.

    I've read that NewAliasMinimal() doesn't always produce acceptable
    AliasHandles, so use NewAlias() to convert an FSSpec into an acceptable
    AliasHandle.
     

    Do a groups.google.com search for my postings on using AESend().

    -- David Phillip Oster
    David Guest

  6. #6

    Default Re: AppleMail and AppleEvents

    Thanks for all the info!

    A question, I'm running a while loop with GetNextProcess() after I
    do a LaunchApplication(). I think I'm running through the list of
    processes before Mail has even started up.

    I'm not sure what to do. Any help would be greatly appreciated!

    My code:

    err = LaunchApplication( &launchMailapp) ;

    psnn.highLongOfPSN = 0;
    psnn.lowLongOfPSN = kNoProcess;

    do {

    err = GetProcessInformation ( &psnn, &pir ) ;

    if (appSignature == pir.processSignature)
    {
    break;
    }

    }
    while ( err != GetNextProcess (&psnn) && appSignature != pir.processSignature ) ;


    David Phillip Oster <org> wrote in message news:<sf.sbcglobal.net>... 
    >
    > 1.) You don't send the Quit in the Launch. If your GetNextProcess()
    > GetProcessInfo loop shows that the process is running, you use AESend()
    > to send it events.
    >
    > 2.) kAEOpenDoents is defined to take an AEList of file specifiers,
    > but in OS X, FSSpecs aren't meaningful is sent from one process to
    > another. You need to put an AEList of AEDescriptors of AliasHandles as
    > the direct object parameter of the appleEvent that you are coercing to a
    > typeAppParameters.
    >
    > I've read that NewAliasMinimal() doesn't always produce acceptable
    > AliasHandles, so use NewAlias() to convert an FSSpec into an acceptable
    > AliasHandle.

    >
    > Do a groups.google.com search for my postings on using AESend().
    >
    > -- David Phillip Oster[/ref]
    V.Vill Guest

  7. #7

    Default Re: AppleMail and AppleEvents

    In article <google.com>,
    com (V.Vill) wrote:
     

    You should instead use a Carbon event handler for
    kEventClassApplication/kEventAppLaunchNotification.

    hth

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

Similar Threads

  1. Replies: 4
    Last Post: November 19th, 12:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139