Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

adding link in applescript mail message

Hi everyone! 🙂

I know how to send an email via Mail.app using Applescript. But if I would like to include a link in my message how would I do that? Specifically I would like to include a link that has a general name such as "Click Here" but I would like it to point to a web address of my choice when clicked upon. Hope this makes sense and that someone can help me out...thanks in advance!

Reg

Powerbook G4 12" 1.5GHz 1.25Gb RAM, Mac OS X (10.5.2)

Posted on Aug 30, 2008 1:03 AM

Reply
Question marked as Best reply

Posted on Aug 31, 2008 12:16 AM

Hi,
I thought this link might help you,
http://bbs.macscripter.net/viewtopic.php?pid=102424

If you run the following (taken from the above link) in script editor, it creates a clipboard text (with a link), however I couldn't figure out how to paste the clipboard item in the mail message using applescript,

set theLink to "http://www.hamsoftengineering.com"
set linkText to "click here"

set cmd to "\"{\\rtf1\\ansi\\ansicpg1252\\cocoartf949\\cocoasubrtf270{\\fonttbl\\f0\\fswis s\\fcharset0 Helvetica;}{\\colortbl;\\red255\\green255\\blue255;}\\margl1440\\margr1440\\vie ww9000\\viewh8400\\viewkind0\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx432 0\\tx5040\\tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\ql\\qnatural\\pardirnatural{\ \field{\\*\\fldinst{HYPERLINK \"" & theLink & "\"}}{\\fldrslt\\f0\\fs24 \\cf0 \"" & linkText & "\"}}}\""

do shell script "/bin/bash -c 'echo " & cmd & " | pbcopy -Prefer rtf'"

I wish there was an easier way.
Good luck.
8 replies
Question marked as Best reply

Aug 31, 2008 12:16 AM in response to Reggie Ashworth

Hi,
I thought this link might help you,
http://bbs.macscripter.net/viewtopic.php?pid=102424

If you run the following (taken from the above link) in script editor, it creates a clipboard text (with a link), however I couldn't figure out how to paste the clipboard item in the mail message using applescript,

set theLink to "http://www.hamsoftengineering.com"
set linkText to "click here"

set cmd to "\"{\\rtf1\\ansi\\ansicpg1252\\cocoartf949\\cocoasubrtf270{\\fonttbl\\f0\\fswis s\\fcharset0 Helvetica;}{\\colortbl;\\red255\\green255\\blue255;}\\margl1440\\margr1440\\vie ww9000\\viewh8400\\viewkind0\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx432 0\\tx5040\\tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\ql\\qnatural\\pardirnatural{\ \field{\\*\\fldinst{HYPERLINK \"" & theLink & "\"}}{\\fldrslt\\f0\\fs24 \\cf0 \"" & linkText & "\"}}}\""

do shell script "/bin/bash -c 'echo " & cmd & " | pbcopy -Prefer rtf'"

I wish there was an easier way.
Good luck.

Aug 31, 2008 12:24 AM in response to Ahsan

Thank you very much for your reply! 🙂

I've been looking around and trying to figure this out...there may be an easier approach on how to do this. I can actually make a draft in Mail.app and save it that has all the things that I need in it. What I would need to do is to make Applescript access that saved draft in within Mail.app and insert a To: address and send it...maybe this is easier? I do know how to create a new message and send it using Applescript but how to access a currently saved draft and just insert an address and send it away...any thoughts?

Thanks again,

Reg 🙂

Sep 1, 2008 7:24 AM in response to red_menace

Hi again everyone! 🙂

I do appreciate all the help...but still I'm stuck. I can't find a way to insert a link into a new mail message created via Applescript even using all your advice. Maybe I'm missing something? Another way I've tried is to access a previously saved draft message and just send that out but unfortunately I can't figure out how to turn that into an outgoing message that I can add a recipient and send it... 😟

Any more ideas???

Reg

Sep 1, 2008 7:52 AM in response to Reggie Ashworth

I just tested my idea and it works... It's show as mailto but it works.
how to get it in applescript without shown mailto I don't know.

I took the standard apple script Create New Message.scpt and put my code in the body. Then I received the email and I can click on the link - it's works.

I can not use the code because it's html and the forum interpreted it has code.
but when you use < mailto:xxx@xxx.com > That's the same when making websites...

So use in place of the ' ' ('mailto:xxx@xxx.com?subject=YOURSUBJECT')

How to embed the code in previous emails that I don't know.

Sep 1, 2008 9:37 AM in response to Reggie Ashworth

The problem is that although you can put an RTF link on the clipboard, an application needs to know what it is in order to use it as a link. You can paste the link into various applications, but unfortunately AppleScript isn't one that understands it, so you can't just put the link text into one of the properties of your message. GUI scripting the New Message window can be a pain, as is most GUI scripting, so maybe using signatures will do the trick.

Once you get the link text onto the clipboard (using this script from Ahsan's post above, for example), go into Mail's preferences, create a signature, and paste the link into it. Then, just modify your own script to include it, for example:

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
tell application "Mail"
set theSubject to "some subject"
set theContent to return & "test" & return & "testing" & return
set theSignature to signature "Signature #1"

tell (make new outgoing message)
set visible to true
set subject to theSubject
set content to theContent
set message signature to theSignature
end tell
activate
end tell
</pre>

I used a default signature name "Signature #1" in the above example - change it to one of your signatures (obviously). There is also an example Mail script in /Library/Scripts/Mail Scripts/Create New Message.scpt you can use to get the various properties into your outgoing message.

Sep 1, 2008 10:42 AM in response to red_menace

Hi again!

Ok I think maybe I've got it to work in a slightly different way based on all your help...please tell me how this sounds...since the email I want to send is not that long it seems I can just create a signature that contains all the wording/formatting/positioning I need and have it pre-saved. Then when I prepare my new message via Applescript instead of inputting content I can just attach my signature to the outgoing message and automatically it will be the way I want it then I can just send it away...how does that sound??? Thanks again for your input!

Reg

adding link in applescript mail message

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.