1

I have a piece of applescript that creates a new mail message and then loads a template into that message.

So far so good.

I want to get the content ( body text ) after the template being loaded. How can I get the body content after loading the template? Reason is, I need to replace some text ("/date/") with a date.

The body could be HTML or just plain text.

I know how to get the content when an existing mail is selected, so it is questioned really only about this case.

BTW, a secondary question. Now I use button click to load the template, but is there a better way, for example load the template directly by name?

Thank you very much

edit addition

I'am a step further. It is solved for this problem.

First I did make a new email using 
tell application mail
   -- make email and visible
   -- then for using the keystrokes and gui to get the template
   tell application system events
      tell process mail 
      -- tell window to get template - works fine
      -- SEE NOTE 1
      set _content to content of myMessage -- it doesn't work, message ID is there
      set the _content to (get the value of the last scroll area)  -- it doesn't work
      -- IN HERE I CANT'T get the content of the message, should be with the ui?
      -- if someone knows, please
      end tell
   end tell
   -- now I have to Activate the mail app. I didn't know
   activate --
   set _content to content of myMessage -- works
   set the clipboard to _content as string -- works almost
   --  SEE NOTE2

Note 1 In here I can't get the content of the message, should be with the ui? if someone knows, please

Note 2 If I paste the clipboard, the text has a different font. How can I get the right type of font in my clipboard?

Still searching for a better way for getting the template.

Lord iPhonius
  • 173
  • 2
  • 11
  • I'd suggest pasting relevant portions of your current code. – jweaks Jun 05 '14 at 03:05
  • pasted extra information – Lord iPhonius Jun 05 '14 at 10:47
  • Not sure if a template is the same as a signature, but you can get a signature like `set message signature of newMail to signature `. Also: You try to get the content in the SystemEvents tell block. You get it only in the tell app Mail block outside the SystemEvents block. – user309603 Jun 05 '14 at 13:14
  • Unfortunate, it's not. Not even a mention about Stationaries in the docs, as far as I can see. – Lord iPhonius Jun 05 '14 at 19:47
  • Can you post the complete code you have thus far? Easier for us to help rather then trying recreate what you already have working. – dscl Jun 11 '14 at 01:41

1 Answers1

0

I answered a similar question here

https://stackoverflow.com/a/23069553/348694

The trick there was to use a preformatted rtf file, copy it to the clipboard and then paste it in the message.

This way you can easily change the content with a search/replace before you copy it into the clipboard for pasting.

HTH

Community
  • 1
  • 1
Dude named Ben
  • 507
  • 3
  • 16