10 Replies Latest reply on Mar 29, 2016 4:17 AM by user19752

    Applescript for default email

    AndrewJudd

      Hi all,

       

      I have the below applescript (bottom of post) which works fine with Mac Mail. I was wondering how to make the script choose the default email program a user might be using. Hunting around online I found this -

       

      on run
        set mailClient to getDefaultMailClient() -- store application id
        tell application id mailClient to activate -- tell mail client to do something
      end run

       

      but I'm not sure how to piece it all together?

       

      Anyone have any ideas?

       

      Thanks!

       

       

       

       

      -- tell application "FileMaker Pro Advanced"

      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 & return & return

      -- otherwise it jams it up against the text

       

      tell application "Mail"

      activate

          set newMessage to make new outgoing message with properties {content:theMessage}

          tell newMessage

      tell content

                  repeat with i in attachmentList

                      make new attachment with properties {file name:i} at after the last paragraph

                  end repeat

              end tell

       

              save newMessage

              -- send newMessage

              -- switch the commenting on the above 2 lines to send immediately

          end tell

      end tell

        • 1. Re: Applescript for default email
          user19752

          How about changing the line

           

          tell application "Mail"

           

          to

           

          tell application id getDefaultMailClient()

          • 2. Re: Applescript for default email
            AndrewJudd

            thanks, yes but you need to tell the script to look for and find the default email program at the beginning somehow.

            • 3. Re: Applescript for default email
              user19752

              You seems got the code from http://stackoverflow.com/questions/3986512/how-do-i-get-the-default-mail-client-using-applescript

               

              Did you add the function definition before (or after?) your applescript?

               

              on getDefaultMailClient()
                set prefPath to (path to preferences as text) & "com.apple.LaunchServices.plist"
                tell application "System Events"
                try
                value of property list item "LSHandlerRoleAll" of ¬
                (first property list item of property list item "LSHandlers" of ¬
                property list file prefPath whose value of property list items ¬
                contains "mailto")
                on error
                "com.apple.mail"
                end try
                end tell
              end getDefaultMailClient


              --start your applescript here

              • 4. Re: Applescript for default email
                AndrewJudd

                thanks, so then you would have the below?  One problem..

                 

                - It highlights "message" in the set new message line saying expecting an end of line here.

                 

                Any ideas?

                 

                 

                 

                 

                Screen Shot 2016-03-29 at 08.25.08.png

                 

                 

                 

                 

                 

                 

                on getDefaultMailClient()

                  set prefPath to (path to preferences as text) & "com.apple.LaunchServices.plist"

                  tell application "System Events"

                  try

                  value of property list item "LSHandlerRoleAll" of ¬

                  (first property list item of property list item "LSHandlers" of ¬

                  property list file prefPath whose value of property list items ¬

                  contains "mailto")

                  on error

                  "com.apple.mail"

                  end try

                  end tell

                end getDefaultMailClient

                 

                -- tell application "FileMaker Pro Advanced"

                set theMessage to cell "Message" of current record

                set theAttachments to cell "Attachments" of current record

                -- return-separated Mac:file paths

                -- end tell

                 

                -- 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 theAttachment to theAttachment & return

                set theMessage to theMessage

                 

                tell application "getDefaultMailClient"

                activate

                    set newMessage to make new outgoing message with properties {content:theMessage}

                    tell newMessage

                tell content

                            repeat with i in attachmentList

                                make new attachment with properties {file name:i}

                            end repeat

                        end tell

                 

                        save newMessage

                        end tell

                end tell

                • 5. Re: Applescript for default email
                  user19752

                  What mail client do you use?

                   

                  Each mail client have its own word of applescript, many of standard suits may be supported but not all, nothing at worst case. So you need to modify script for each client.

                  • 6. Re: Applescript for default email
                    AndrewJudd

                    thanks yes. Tobe honest I think most of my clients will be using mail but if it could have worked to find the default that would have been great. Do you know how to use the below AppleScript for file maker go? It doesn't seen to work by leaving it as mail. ie no email gets created. I can script it so it has an if - Patter count - iPad etc and it goes to a different AppleScript but just need to adjust the below. Thanks!

                    • 7. Re: Applescript for default email
                      user19752

                      "Perform AppleScript" step works on only OSX, FMGo can't perform it.

                      • 8. Re: Applescript for default email
                        AndrewJudd

                        i see. That's frustrating. Ok so when using FMgo it might just have to be the classic send mail step (therefor restricted to one attachment). Thanks for your help

                        • 9. Re: Applescript for default email
                          AndrewJudd

                          aalso, out of interest, if a user is on a PC, is everything ruled out?

                          • 10. Re: Applescript for default email
                            user19752

                            If you send mail via SMTP (not use client), it is easy in Windows.

                            HTML Email in FileMaker for Windows

                            (I haven't seen the attached file)