• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Data Rich email like iPhoto/Aperture?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Data Rich email like iPhoto/Aperture?


  • Subject: Re: Data Rich email like iPhoto/Aperture?
  • From: Martin Redington <email@hidden>
  • Date: Fri, 2 Nov 2007 16:35:45 +0000


On 2 Nov 2007, at 07:58, Thomas Engelmeier wrote:


On 01.11.2007, at 06:19, Ben Lachman wrote:

I'd like to push some attributed strings into an email for my users to address and send out... something like what iPhoto or Aperture do. I have an applescript that will attach a file, but it won't inline it.

- I'd guess Aperture and iPhoto use helper AppleScripts to talk to the Mail clients. Find those and analyze those.
- if you cannot open them, set AEDebug and friends in the environment and see the events that are sent in order to compose a Mail you want to mimick.


Regards,
	Tom_E


Something like this should work (you'll have to fiddle with the constants and macros - I just cut and pasted from my code).

I'm pretty sure that the AppleScript was adapted from a sample online, but I don't have the original reference.



- (BOOL) sendMailUsingAppleMailTo:(NSString *)toAddress from: (NSString *)fromAddress path:(NSString *)path subject:(NSString *) theSubject message:(NSString *)theMessage
{
NSString *scriptPath = [[NSBundle mainBundle] pathForResource:kIrisSendAppleMailScript ofType:kIrisSendAppleMailScriptSuffix];
NSAssert2(scriptPath != nil, @"Could not find %@.%@ in Resources", kIrisSendAppleMailScript, kIrisSendAppleMailScriptSuffix);


NSURL* url = [NSURL fileURLWithPath:scriptPath];
NSAssert1(url != nil, @"Could not transform %@ into a URL", scriptPath);


NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript =
[[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];


NSAssert1(appleScript != nil, @"Applescript would not compile: % @", errors);

// create the first parameter
NSAppleEventDescriptor* theSenderAddressDescriptor = [NSAppleEventDescriptor descriptorWithString:fromAddress];
NSAppleEventDescriptor* theAddressDescriptor = [NSAppleEventDescriptor descriptorWithString:toAddress];


NSAppleEventDescriptor* theMessageDescriptor = [NSAppleEventDescriptor descriptorWithString:theMessage];

NSAppleEventDescriptor* theSubjectDescriptor = [NSAppleEventDescriptor descriptorWithString:theSubject];

NSAppleEventDescriptor* theAttachment = [NSAppleEventDescriptor descriptorWithString:path];

// create and populate the list of parameters (in our case just one)
NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor listDescriptor];
int index = 1;
[parameters insertDescriptor:theSenderAddressDescriptor atIndex:index++];
[parameters insertDescriptor:theAddressDescriptor atIndex:index++];
[parameters insertDescriptor:theSubjectDescriptor atIndex:index++];
[parameters insertDescriptor:theMessageDescriptor atIndex:index++];
[parameters insertDescriptor:theAttachment atIndex:index++];


// create the AppleEvent target
ProcessSerialNumber psn = {0, kCurrentProcess};
NSAppleEventDescriptor* target =
[NSAppleEventDescriptor descriptorWithDescriptorType:typeProcessSerialNumber
bytes:&psn
length:sizeof (ProcessSerialNumber)];


// create an NSAppleEventDescriptor with the script's method name to call,
// this is used for the script statement: "on show_message (user_message)"
// Note that the routine name must be in lower case.



NSAppleEventDescriptor* handler =
[NSAppleEventDescriptor descriptorWithString: [kIrisSendAppleMailRoutineName lowercaseString]];


// create the event for an AppleScript subroutine,
// set the method name and the list of parameters
NSAppleEventDescriptor* event =
[NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite
eventID:kASSubroutineEvent
targetDescriptor:target
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
[event setParamDescriptor:handler forKeyword:keyASSubroutineName];
[event setParamDescriptor:parameters forKeyword:keyDirectObject];


// call the event in AppleScript
if (![appleScript executeAppleEvent:event error:&errors]);
{
// report any errors from 'errors'
GALLERYWINDOWCONTROLLERLOG(@"Applescript execution failed: % @", errors);
}


    [appleScript release];

    return YES;
}

====


on newMessage(theSenderAddress, theAddress, theSubject, theBody, theAttachment)
tell application "Mail"

set theSender to (theSenderAddress & " <" & theSenderAddress & ">") as string

-- Find the Sending address
set everyAccount to every account
repeat with eachAccount in everyAccount
set everyEmailAddress to email addresses of eachAccount
if (everyEmailAddress is not equal to missing value) then
repeat with eachEmailAddress in everyEmailAddress
if eachEmailAddress is equal to theSenderAddress then
set theSender to (full name of eachAccount & " <" & eachEmailAddress & ">") as string
end if
end repeat
end if
end repeat

-- We should check the sender here. TODO!!!

-- Properties can be specified in a record when creating the message or
-- afterwards by setting individual property values.
set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell newMessage
-- Default is false. Determines whether the compose window will
-- show on the screen or whether it will happen in the background.
set visible to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
tell content
if (theAttachment is not equal to "") then
-- Position must be specified for attachments
make new attachment with properties {file name:theAttachment} at after the last paragraph
end if
end tell

end tell

-- Bring the new compose window to the foreground, in all its glory
activate
end tell
end newMessage



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Data Rich email like iPhoto/Aperture? (From: Thomas Engelmeier <email@hidden>)

  • Prev by Date: NSWindow not being shown on Intel Mac
  • Next by Date: Re: IB Palettes no longer supported in Leopard - what to do?
  • Previous by thread: Re: Data Rich email like iPhoto/Aperture?
  • Next by thread: Re: [Leopard] Core Data model versioning vs. NSPersistentDocument
  • Index(es):
    • Date
    • Thread