0

I've been searching the internet but am having trouble finding a way to attach a URL hyperlink to a new email using applescript.

The most helpful link I've found is from 2008, and I believe the poster was eventually able to add a hyperlink, but only within a mail signature.

https://discussions.apple.com/thread/1687240

I am already using another mail signature and I'm wondering if there is some other way to do this since it's been 10 years since the original post.

This is an example of my code:

*please note: the file attachment in the code is only for purposes of attaching an image, and is separate from my question about adding a URL hyperlink.


property thesender : "Belinda "

tell application "Microsoft Excel" set lasty to first row index of (get end (last cell of column 1 of sheet 1) direction toward the top) end tell

repeat with i from 2 to lasty

tell application "Microsoft Excel"

    set pername to value of column 1 of row i of sheet 1 of active workbook as text

    set peremail to value of column 2 of row i of sheet 1 of active workbook as text


end tell


tell application "Mail"

    set theAttachmentFile to "Macintosh HD:Users:abc:Desktop:Photos:abc.jpg"

    set signatory to "CXO"

    set newemail to make new outgoing message with properties {content:"Hi" & space & pername & "," & return & return & "I hope all is well.  My name is Belinda with Company X. We recently published a peer-based Technologies Survey that I thought you would find valuable & wanted to share." & return & return & return & return & "Download your copy of the survey here: Technologies Survey Powered by Company X.

Please reach out with any questions or if you’d like to learn how our AI-based platform is helping your peers optimize spend.

I look forward to connecting.

Thanks, Belinda", visible:true, subject:"ABC Survey Results for" & space & pername, message signature:signature signatory}

    tell content of newemail
        make new attachment with properties {file name:theAttachmentFile as alias} at after sixth paragraph
    end tell

    set sender of newemail to thesender

    tell newemail

        make new to recipient at end of to recipients with properties {name:pername, address:peremail}

    end tell

end tell

end repeat


'I need the hyperlink to sit within the message content where it says "Download your copy of the survey here."

Any help would be greatly appreciated!

  • What are you hyperlinking to? The file theAttachmentFile? Or is there some other URL that I am missing? – Chris Norman Jun 1 at 21:25
  • No, the attachment file is just to insert an image within the email. I need to attach a website URL hyperlink to the part of the message content that says "Download your copy of the TBM Survey here" – Belinda Wallace Jun 1 at 22:00
  • I do not use the macOS built-in Mail app; however, its AppleScript Dictionary does not even contain an Add Link verb and I saw nothing else that looked like it was on point for adding a hyperlink. That said, the Mail app does have an Add Link… command in its Edit menu. You could use UI Scripting, (which I only use if there is no other way), i.e., having AppleScript click the menu item and fill in the ensuing dialog box, etc. Since I do not use Mail that's about the only suggestion I have for you. – user3439894 Jun 1 at 22:54
  • @BelindaWallace Can the link be somehow first be in clipboard? I think pasting it be easier. No prior experience in AppleScript though. – ankiiiiiii Jun 2 at 15:11
  • So make the URL into a variable and then add that variable to the content of the message. Kind of like how you have done for the variable "pername". – Chris Norman Jun 2 at 19:26

You must log in to answer this question.

Browse other questions tagged .