Jump to content

Recommended Posts

Hi, my first post is a little bit long, but I spent some days in Google before posting here, so I hope to get help.


I am trying to create workflow using AppleScript that creates Mail message for me with some links in the footer of the mail body. 
The problem is that I can't insert links this way, because it places this html as Plain text instead of Rich text:
set FooterText to "<a href=\"http://example.com\">Example link</a>"
I was trying to find a way to convert html text to Rich text, and found that it can be done with "textutil" from a Terminal app.
Running this command from Terminal app works fine:
echo '<a href="http://example.com">Example link</a>'|textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout|LC_CTYPE=UTF-8 pbcopy

I can then open Mail app and paste "Example link" as a rich text, and this link is working.


However I can't do the same using "do shell script" from Applescript (NSAppleScript). 

First I thought it is something to do with escaping characters, so I did a test with <b>bold</b>, but it didn't work, too.
Then instead of using "do shell script" I tried "do script" by telling application "Terminal" same script that was working in Terminal app, but it doesn't work from AppleScript, too:
on alfred_script(q)

set myHtmlText to "<b>bold example</b>"
tell application "Terminal"
   do script "echo " & quoted form of myHtmlText & |textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout|LC_CTYPE=UTF-8 pbcopy"
end tell

end alfred_script
Error msg says: "Expected end of line but found identifier." pointing to "|" before LC_CTYPE
Any ideas why it is not working?


Thanks in advance,



Share this post

Link to post

You forgot to open the quotes. Instead of

do script "echo " & quoted form of myHtmlText & |textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout|LC_CTYPE=UTF-8 pbcopy"

it should read (note the quote mark preceding |textutil)

do script "echo " & quoted form of myHtmlText & "|textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout|LC_CTYPE=UTF-8 pbcopy"

You don’t need tell Terminal or alfred_script(q), though. You can replace everything with a Run Script using /usr/bin/osascript as the language (as opposed to a Run NSApplescript) and 

set myHtmlText to "<b>bold example</b>"
do shell script "echo " & quoted form of myHtmlText & "|textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout|LC_CTYPE=UTF-8 pbcopy"

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...