View Single Post
In the OmniFocus main menu,
Edit > Copy As Link
is invaluable, placing a link like omnifocus:///task/ft9gpCMAZSF in the clipboard.

Useful as it is to be able to jump straight to an OF folder, project, task or context from another application, these raw links are dauntingly illegible, and give little clue to the identity of their target.

This script works just like Edit > Copy As Link, but the RTF-formatted links which it places in the clipboard hide the raw url behind the human-readable name of the target task, project, context or folder. They can be pasted into any rich text editor or field, such as OF notes, OO3 rows or notes, or in TextEdit, DevonThink, etc.

If several items are selected in the OF content panel, a series of links on different lines will be copied to the clipboard. If nothing is selected in the content panel, links for any sidebar selections will be copied.

(The same thing can be achieved by dragging out of OF into a rich text editor, but my patience for mice and the time they waste is short :-)

In fact, I now notice that Cmd C does this anyway, so the above is really just an idle curiosity :-)

Code:
on run
	CopyAsRTFLabelledLink()
end run

-- MAKE AN RTF LABELLED LINK TO THE ITEM(S) SELECTED IN THE OF CONTENT PANEL
-- (Such links can be pasted into rich text editors like OO3, TextEdit etc)
-- (If nothing is selected in the content panel, links are made for any selections in the sidebar)
on CopyAsRTFLabelledLink()
	tell application id "com.omnigroup.omnifocus"
		tell front document window of front document
			repeat with oPanel in {content, sidebar}
				set refSeln to (a reference to selected trees of oPanel)
				if (count of refSeln) > 0 then exit repeat
			end repeat
			if (count of refSeln) < 1 then return
			set lstObjects to value of refSeln
		end tell
		set strHTML to ""
		repeat with oSeln in lstObjects
			tell oSeln
				set strClass to class as string
				if strClass = "project" then set strClass to "task"
				if strClass is in {"folder", "task", "context"} then set strHTML to strHTML & ¬
					"<font face=\"Helvetica\"><a href=\"" & "omnifocus:///" & strClass & "/" & ¬
					id & "\">" & name & "</a></font><br>" & linefeed
			end tell
		end repeat
	end tell
	do shell script "echo " & quoted form of strHTML & "  | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
end CopyAsRTFLabelledLink

Last edited by RobTrew; 2011-02-12 at 08:47 AM.. Reason: slight edit to code (class <> item --> class is in folder|task|context)