Adding a named link to Notes
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 [INDENT][url]http://omnifocus.com[/url][/INDENT] I'd get [INDENT][URL="http://omnifocus.com"]OmniFocus[/URL][/INDENT] (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[/CODE] (Is is true, incidentally, that the [I].text[/I] 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 [url]http://bit.ly/OFOC-Devon[/url]) 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 [/CODE] |
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[/CODE] |
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 [/CODE] |
[QUOTE=RobTrew;127165]Or perhaps more legibly:[/QUOTE]
Wow Rob, that's brilliant. Thanks! |
All times are GMT -8. The time now is 02:43 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.