13 Replies Latest reply on Aug 18, 2017 1:32 PM by APIcoder

    HTML with applescript

    AndrewJudd

      hi all, I use the below applescript to create emails using a solution. I wondered if it is possible to adapt it slightly so the new email is HTML and I can therefore include formatted text (in italic) into the email.

       

      Any suggestions welcome. thank you.

       

       

       

       

      -- tell application "FileMaker Pro"

      set theMessage to cell "Message" of current record

      set theAttachments to cell "Attachments" of current record

      -- return-separated Mac:file paths

      -- end tell

       

       

      set attachmentList to {}

      repeat with i in paragraphs of theAttachments

      set theAttachment to i

      set aliasAttachment to theAttachment as alias

      set attachmentList to attachmentList & aliasAttachment

      end repeat

       

       

      set theMessage to theMessage

       

       

      set additionalParagraphs to return & return

      repeat (count attachmentList) times

         set additionalParagraphs to additionalParagraphs & return & return

      end repeat

       

       

      tell application "Mail"

         activate

         set newMessage to make new outgoing message with properties {content:additionalParagraphs & theMessage, visible:true}

         tell newMessage

             repeat with i from 1 to (count attachmentList)

                 tell content

                     make new attachment with properties {file name:item i of attachmentList} at after paragraph (i *2 )

       

       

                 end tell

             end repeat

            

       

       

             save newMessage

      end tell

      end tell

        • 1. Re: HTML with applescript
          karina

          Hi,

           

          You can use a HMTL code in a new HMTL message field and combine with the value off the original message field.

          The use the new HTMLmessage field in your Applescript.

           

          Greetz,

          Karina

          • 2. Re: HTML with applescript
            karina

            HMLT = HTML

            • 3. Re: HTML with applescript
              beverly

              That just confused me. LOL. I'm lysdexic & I read it correctly the first time.

               

              Sent from miPhone

              • 4. Re: HTML with applescript
                karina

                Hi Andrew,

                 

                Forget to you should create the HTMLmessage field in FM:

                Here's a sample HTML:

                "

                <html>

                  <head>

                  <style>

                  body {font-family:Tahoma;font-size:12px;}

                  table {font-family:Tahoma;font-size:12px;}

                  </style>

                  </head>

                  <body>" &

                  "Dear " & Table one::Message reciever name & "," & "<br><br><i>" &

                  Table one::Message & "</i><br><br>

                  Kind regards,<br><br><b>" & Table one::From text & "</b><br>" & Table one::Department & "<br>

                  </body>

                </html>

                "

                And this is the result:

                 

                Screen Shot 2017-08-13 at 17.13.36.png

                • 5. Re: HTML with applescript
                  karina

                   

                  • 6. Re: HTML with applescript
                    AndrewJudd

                    Thank you, could you explain a little bit more on how to implement into the AppleScript?

                    • 7. Re: HTML with applescript
                      karina

                      Hi,

                      Does your Apple Script you posted work?

                      Greetz,

                      Karina

                      • 8. Re: HTML with applescript
                        AndrewJudd

                        yes, but I'm not sure exactly how to adjust for HTML. At the moment I'm just getting your HTML message in plain text in an email rather than knowing it its HTML and showing it at such..

                         

                         

                        Screen Shot 2017-08-13 at 18.55.06.png

                        • 9. Re: HTML with applescript
                          karina

                          Hi,

                           

                          I just created this Apple script en sample.

                          And it works with outlook

                           

                          tell application "FileMaker Pro Advanced"

                            set theMessage to cell "HTMLMessage" of current record

                          end tell

                           

                          set theFile1 to "/Users/karina/Desktop/Hello.pdf" as POSIX file

                          set theFile2 to "/Users/karina/Desktop/Hell2.pdf" as POSIX file

                           

                          tell application "Microsoft Outlook"

                            set newMessage to make new outgoing message with properties {subject:"test"}

                            make new recipient at newMessage with properties {email address:{address:"test@test.nl"}}

                            set content of newMessage to theMessage

                            delay (2)

                            tell newMessage

                            make new attachment with properties {file:theFile1}

                            end tell

                            tell newMessage

                            make new attachment with properties {file:theFile2}

                            end tell

                            open newMessage

                            get newMessage

                          end tell

                           

                          I should reinstall mail to check if this also works with mail.

                           

                          Greetz,

                           

                          Karina

                          • 10. Re: HTML with applescript
                            karina

                            Hi,

                             

                            I just tried it with mail, and I failed

                            Look's like Apple mail doesn't support HTML, but I could be wrong.

                             

                            I goggled for it and found solutions like "write a script to open the page in Safari and then send it with mail" sound's like a real big workaround.

                             

                            Maybe somebody else has a solution, the only other thing I can think of is, try it with outlook.

                             

                            Sorry that I couldn't help you, hope somebody else can.

                             

                            Greetz

                            Karina

                            • 11. Re: HTML with applescript
                              AndrewJudd

                              Thanks very much for all the efforts on this!

                              • 12. Re: HTML with applescript
                                AndrewJudd

                                as a chance of strategy I am seeing If I can use AppleScript to copy to clipboard a particular cell (field in the database) and then paste into my new email. So far I have the below which isn't working -

                                 

                                 

                                 

                                -- tell application "FileMaker Pro"

                                set theAttachments to cell "Attachments" of current record

                                set the clipboard to cell "Message" of current record

                                  -- return-separated Mac:file paths

                                -- end tell

                                 

                                 

                                set attachmentList to {}

                                repeat with i in paragraphs of theAttachments

                                  set theAttachment to i

                                  set aliasAttachment to theAttachment as alias

                                  set attachmentList to attachmentList & aliasAttachment

                                end repeat

                                 

                                 

                                set additionalParagraphs to return & return

                                repeat (count attachmentList) times

                                   set additionalParagraphs to additionalParagraphs & return & return

                                end repeat

                                 

                                 

                                tell application "Mail"

                                   activate

                                   set newMessage to make new outgoing message with properties {content:additionalParagraphs &  the clipboard, visible:true}

                                   tell newMessage

                                       repeat with i from 1 to (count attachmentList)

                                           tell content

                                               make new attachment with properties {file name:item i of attachmentList} at after paragraph (i *2 )

                                end tell

                                       end repeat

                                      

                                 

                                save newMessage

                                end tell

                                end tell

                                • 13. Re: HTML with applescript
                                  APIcoder

                                  This works with simple HTML pages:

                                  It's is a work around

                                   

                                  tell application "Safari"

                                      activate

                                      try

                                          open POSIX path of (((path to desktop folder) & "mail.html") as string) -- mail.html is your html page

                                          delay 5

                                      on error someError

                                          display dialog someError

                                          return

                                      end try

                                  end tell

                                   

                                   

                                  tell application "System Events"

                                      tell process "Safari"

                                          set frontmost to true

                                          click menu item "Email This Page" of menu of menu item "Share" of menu "File" of menu bar 1

                                          -- Dutch

                                          -- click menu item "E-mail deze pagina" of menu of menu item "Deel" of menu "Archief" of menu bar 1

                                      end tell

                                  end tell

                                   

                                  André