Making link clickable in OF2

This isn’t really Applescript, but it is development related.

I’m playing with a Ruby script that parses an email folder and creates OF tasks from the messages within. I want to take the message ID and add a link to the notes section of a new task. Basically, the script sends an email to the Omni Sync Server email address I have for Mail Drop so a new task is created. Is there a special way to make that link the to message clickable once in OF2? Right now just putting the message URL in the body of the email works, OF makes it clickable. I’d like to have it be maybe text that states “Original Message” or something. Using an HTLM Hyperlink does not work.

How are you using Ruby to make the tasks? HTML does work, but you have to paste it in as html.

I’ve been working on this for a few days – a few minutes here and there – and can’t quite get it. OmniFocus uses rich text notes. Using textutil I can successfully get rich text links onto my clipboard that paste into OmniFocus and TextEdit just fine:

set html_note to quoted form of "<a target=\"_blank\" href=\"http://n8henrie.com\">My Website</a>"

do shell script "echo " & html_note & " | textutil -stdin -stdout -format html -convert rtf | pbcopy"

However, I get a bunch of gobbledygook when I try to put it directly into the note field (in both OF and TextEdit):

set html_note to quoted form of "<a target=\"_blank\" href=\"http://n8henrie.com\">My Website</a>"

set rtf_note to (do shell script "echo " & html_note & " | textutil -stdin -stdout -format html -convert rtf")

tell application "OmniFocus"
	tell default document
		make new inbox task with properties {name:"Figure out how to put HTML links in OmniFocus notes", note:rtf_note}
	end tell
end tell

Output note:

{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf200
{\fonttbl\f0\froman\fcharset0 Times-Roman;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue233;}
\deftab720
\pard\pardeftab720
{\field{\*\fldinst{HYPERLINK "http://n8henrie.com/"}}{\fldrslt 
\f0\fs24 \cf2 \ul \ulc2 My Website}}}

If anybody can chime in and let me know what I’m missing, that would be great.

I’ve gotten one step farther with «as class RTF » (for some ridiculous reason I have to have a space after RTF), but still can’t get it into OmniFocus.

set html_note to "<a target=\"_blank\" href=\"http://n8henrie.com\">My Website</a>"

set rtf_note to (do shell script "echo " & quoted form of html_note & " | textutil -stdin -stdout -format html -convert rtf" as «class RTF »)

I’ve tried every combination of as rich text, as «class RTF », as «class HTML», trying to set it to the clipboard and use pbcopy… I am getting nowhere. I’ve tried piping to hexdump and going that route with no luck…

I have even manually pasted in a (working) hyperlink, then tried to reverse engineer it with:

tell application "OmniFocus"	
	tell default document

		set my_task to first inbox task whose name contains "HTML"		
		properties of note of my_task
		
	end tell	
end tell```

Unfortunately, the properties don't have any mention of the hyperlink, where it goes, or how I can take my rich text variable and make it into a note.

I'm pretty frustrated, this seems to be stupid hard to figure out. To me, it doesn't look like Omni has made this possible with the OF2 AppleScript support. Would love to get proved wrong here.

This seems to work brilliantly in TextEdit, not sure why OmniFocus is choking:

set html_note to "<a target=\"_blank\" href=\"http://n8henrie.com\">My Website</a>"

set rtf_note to (do shell script "echo " & quoted form of html_note & " | textutil -stdin -stdout -format html -convert rtf" as «class RTF »)

tell application "TextEdit"
	activate
	
	set my_document to make new document
	tell my_document
		
		set first text to rtf_note
		
	end tell
	
end tell```

There has been a bug in OmniFocus where a newly added URL doesn’t become a clickable link until you click into and out of the note field once. Is it possible you’re hitting that?

I’m familiar with that bug, but this isn’t it. I either get an AppleScript error, or I get

{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf200
{\fonttbl\f0\froman\fcharset0 Times-Roman;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue233;}
\deftab720
\pard\pardeftab720
{\field{\*\fldinst{HYPERLINK "http://n8henrie.com/"}}{\fldrslt 
\f0\fs24 \cf2 \ul \ulc2 My Website}}}

But nothing resembling a link. If I pipe to pbcopy and manually paste in the link, it works fine. However, OmniFocus appears unable to handle passing in the rich text, even thought that’s supposedly the data type of the note (and it handles it fine when pasted manually).

Did anyone crack this problem yet? I was trying to this evening and ran into the same issues.

Would this work for you?

set value of attribute named "link" of style of paragraph 1 of note of myTask to urlString

The available attributes are, as far as I’m aware,

"baseline-offset"
"baseline-superscript"
"children-style-identifier(com.omnigroup.OmniOutliner)"
"font-condensed"
"font-expansion"
"font-family"
"font-fill"
"font-fixed-pitch"
"font-italic"
"font-name"
"font-narrow"
"font-obliqueness"
"font-size"
"font-stroke"
"font-stroke-width"
"font-weight"
"item-child-indentation(com.omnigroup.OmniOutliner)"
"item-child-indentation-allowed(com.omnigroup.OmniOutliner)"
"item-gutter-color(com.omnigroup.OmniOutliner)"
"item-handle-mode(com.omnigroup.OmniOutliner)"
"item-note-indentation(com.omnigroup.OmniOutliner)"
"item-page-break(com.omnigroup.OmniOutliner)"
"item-post-children-adjustment(com.omnigroup.OmniOutliner)"
"item-post-gap(com.omnigroup.OmniOutliner)"
"item-pre-children-adjustment(com.omnigroup.OmniOutliner)"
"item-pre-children-gap(com.omnigroup.OmniOutliner)"
"item-pre-gap(com.omnigroup.OmniOutliner)"
"item-row-padding(com.omnigroup.OmniOutliner)"
"item-row-spacing(com.omnigroup.OmniOutliner)"
"item-to-note-space(com.omnigroup.OmniOutliner)"
"kerning-adjust"
"ligature-selection"
"link"
"next-peer-style-identifier(com.omnigroup.OmniOutliner)"
"paragraph-alignment"
"paragraph-base-writing-direction"
"paragraph-first-line-head-indent"
"paragraph-head-indent"
"paragraph-line-height-multiple"
"paragraph-line-spacing"
"paragraph-maximum-line-height"
"paragraph-minimum-line-height"
"paragraph-spacing"
"paragraph-spacing-before"
"paragraph-tab-stop-interval"
"paragraph-tab-stops"
"paragraph-tail-indent"
"selection-color"
"shadow-color"
"shadow-offset"
"shadow-radius"
"strikethrough-affinity"
"strikethrough-color"
"strikethrough-pattern"
"strikethrough-style"
"text-background-color"
"text-cell-post-gap(com.omnigroup.OmniOutliner)"
"text-cell-pre-gap(com.omnigroup.OmniOutliner)"
"underline-affinity"
"underline-color"
"underline-pattern"
"underline-style"
3 Likes

That worked well for me amy, thanks :-)