The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Adding a named link to Notes Thread Tools Search this Thread Display Modes
Folks,

I've been digging into this for a few hours, and have come to the conclusion that it's simply not possible to do what I want:

Create a note that has a link that shows up as a highlighted word that's something other than the link itself.

In other words, rather than
http://omnifocus.com
I'd get
OmniFocus
(I'm trying to replicate the behavior you get when dragging in a Mail message, or Evernote note, for example.)

I've tried crafting the HTML myself, inserting as RTF, etc. Nothing works. Oddly, when I ask for the Note from a message that has what I want, I just get back the text, rather than a link, or indeed any type of rich text).

Is this at all possible? I hate having "ugly" URLs exposed as links....
 
An HTML version of the link+label can be converted to RTF by Textutil, and then placed in the clipboard.

Code:
property pTitle : "Put labelled link in clipboard as RTF"
property pVer : "0.1"

set {strURL, strTitle} to {"", ""}

set strURL to text returned of (display dialog "Enter a URL:" default answer "http://" with title pTitle)
set strTitle to text returned of (display dialog "Enter a title for the link:" & linefeed & linefeed & strURL default answer "" with title pTitle)

if (strURL is not "") and (strTitle is not "") then
	set strHTML to quoted form of ("<font face=\"helvetica\"><a href=\"" & strURL & "\">" & strTitle & "</a></font>")
	do shell script "echo " & strHTML & "  | textutil -format html -convert rtf -inputencoding UTF-8 -stdin -stdout | pbcopy -Prefer rtf"
end if

display dialog "Lableled link in clipboard as RTF" buttons {"OK"} default button "OK" with title pTitle & "  ver. " & pVer
(Is is true, incidentally, that the .text property of a rich text field just returns a plain text string, but some reading/writing of text attributes is possible if you work with a reference rather than a direct coercion).
 
PS the script for adding links from OF projects to project notes in DEVONthink (at http://bit.ly/OFOC-Devon) contains an example of scripting the addition of a labelled link to a note (rather than pasting it with ⌘V ).
 
Couple of typos might make more sense like this:

Code:
property pTitle : "Put labelled link in clipboard as RTF"
property pVer : "0.2"

set {strURL, strTitle} to {"", ""}

set strURL to text returned of (display dialog "Enter a URL:" default answer "http://" with title pTitle)
set strTitle to text returned of (display dialog "Enter a title for the link:" & linefeed & linefeed & strURL default answer "" with title pTitle)

if (strURL is not "") and (strTitle is not "") then
	set strHTML to quoted form of ("<font face=\"helvetica\"><a href=\"" & strURL & "\">" & strTitle & "</a></font>")
	do shell script "echo " & strHTML & "  | textutil -format html -convert rtf -inputencoding UTF-8 -stdin -stdout | pbcopy -Prefer rtf"
	
	display dialog "Labelled link in clipboard as RTF" buttons {"OK"} default button "OK" with title pTitle & "  ver. " & pVer
end if
 
Thanks Rob; I did try textutil, but putting the resulting RTF content into the link just gave me, well, RTF content. It wasn't formatted.

Pasting the clipboard means having OF come forward and me pasting; I'm trying to avoid any manual work for this process.

Scripting the paste would mean UI scripting, something that's not doable without turning on Accessibility (and which isn't available in Maveredacted).

(There are always more constraints than meets the eye; sorry for leaving these out.)

Thanks for the ideas!
 
You can still work with references:

Code:
-- select a single task in the content panel of OF, and run

tell application id "OFOC"
	tell default document
		tell front document window
			set oTask to (value of first selected tree of content)
			tell oTask to set refNote to a reference to its note
			
			tell refNote
				insert "OmniGroup " at before paragraphs
				set refWord to a reference to first word
				set oStyle to a reference to style of refWord
				set oLink to a reference to attribute "link" of oStyle
				set value of oLink to "http://www.omnigroup.com"
			end tell
			
		end tell
	end tell
end tell
 
Or perhaps more legibly:

Code:
-- select a single task in the content panel of OF, and run

tell application id "OFOC"
	tell default document
		tell front document window
			set oTask to (value of first selected tree of content)
			tell oTask to set refNote to a reference to its note
			
			set strLabel to "Omni Group "
			set strLink to "http://www.omnigroup.com" as Unicode text
			
			set lngChars to length of strLabel
			tell refNote
				insert strLabel at before paragraphs
				
				tell characters 1 thru lngChars
					tell attribute "link" of its style to set value to strLink
				end tell
			end tell
			
		end tell
	end tell
end tell
 
Quote:
Originally Posted by RobTrew View Post
Or perhaps more legibly:
Wow Rob, that's brilliant. Thanks!
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -8. The time now is 06:02 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.