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

 
Copy as (RTF-formatted) labelled link Thread Tools Search this Thread Display Modes
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 09:47 AM.. Reason: slight edit to code (class <> item --> class is in folder|task|context)
 
Greetings Rob-thanks for taking a look at a solution for one of the major drawbacks that I see to linking both to and from OmniFocus. I've copied the script above, but I am having an issue with the results. As example, one task that I copied the link manually has a URL link of:

omnifocus:///task/g_ceQg3zgW2

When I run the script on the same task and paste the results into a DEVONthink RTF document, I get linked text with the proper task name. However, the link URL gets mugged and appears as:

omnifocus:///«class FCac»/g_ceQg3zgW2

Suggestions on the cause?

Also, have you looked at editing the DEVONthink reminder script to do the same? Formatting the DEVONthink link in the note field of an OmniFocus task as the document name w/link would be sweet also.
 
Hi Greg, I haven't seen that problem, I've just noticed that in OF Cmd C creates a labelled link out of the box anyway, so the script (just updated :-) is really not needed.

(Both methods seem to be working with my installation of OF and DT)

A good point about the DT scripts - I'll take a look.

--

Last edited by RobTrew; 2011-02-12 at 09:57 AM..
 
Quote:
Originally Posted by Greg Jones View Post
Formatting the DEVONthink link in the note field of an OmniFocus task as the document name w/link would be sweet also.
Using Edit > Copy Item Link in DT and pasting into an OF note seems to do this.

Do you have a different work-flow in mind ?
 
Quote:
Originally Posted by Greg Jones View Post
the DEVONthink reminder script
Just remind me which of the scripts you have in mind ?

(The URL column in DT is a text field, so it won't sustain a labelled link, but I may have missed which link you are thinking about).
 
Quote:
Originally Posted by RobTrew View Post
Just remind me which of the scripts you have in mind ?

(The URL column in DT is a text field, so it won't sustain a labelled link, but I may have missed which link you are thinking about).
The 'Add as To Do to OmniFocus' script that ships with DEVONthink. It is in the Reminders folder in the DEVONthink script menu.
 
OK - not one of my scripts - I need to consult Eric Böhnisch-Volkmann about the terms under which he would be happy for a modified version of his script to be posted.

In the meanwhile, here is how you might finish off a script to do that:

Code:
-- Add new to do to OmniFocus
	try
		tell application id "com.omnigroup.OmniFocus"
			if theDelayValue ≥ 0 then
				tell default document to set newTask to make new inbox task with properties {name:theSummary, due date:theDueDate}
			else
				tell default document to set newTask to make new inbox task with properties {name:theSummary}
			end if
		end tell
		my PasteToNote(newTask, theSummary, theURL)
	on error errmsg
		display alert (localized string "OmniFocus is not available.")
	end try
	
on error errmsgs
	display alert (localized string "Error when adding item to OmniFocus") message errmsg
end try

on PasteToNote(oObj, strLegend, strURL)
	set strHTML to quoted form of ("<font face=\"Helvetica\"><a href=\"" & strURL & "\">" & strLegend & "</a></font>")
	do shell script "echo " & strHTML & "  | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
	tell application id "com.omnigroup.OmniFocus"
		set cClass to class of oObj
		if not (cClass is in {task, inbox task, project}) then return
		tell front document window of front document
			if selected view mode identifier ≠ "project" then set selected view mode identifier to "project"
			if cClass is inbox task then
				tell tree 1 of sidebar -- Inbox
					if not selected then set selected to true
				end tell
			else
				if (focus as list) ≠ {} then set focus to {}
				tell tree 2 of sidebar -- Library
					if not selected then set selected to true
				end tell
			end if
			tell content to select {oObj}
		end tell
		activate
	end tell
	tell application id "com.apple.systemevents"
		keystroke "'" using {command down} -- Edit note
		keystroke "v" using {command down} -- Paste
	end tell
end PasteToNote

Last edited by RobTrew; 2011-02-12 at 05:31 PM..
 
Quote:
Originally Posted by RobTrew View Post
I've just noticed that in OmniFocus Cmd C creates a labelled link out of the box anyway, so the script (just updated :-) is really not needed.
But, it turns out that while Cmd C works well for links within OmniFocus, and for links from TextEdit, the picture is more complicated if you are pasting links to OF tasks into OmniOutliner ...
  1. Cmd C in OF
    • Paste with current style in OO3 --> plain unlinked text of task
    • Paste in 003 --> legible link
  2. Running script at start of this thread
    • Paste with current style in OO3 --> legible link to task
    • Paste in 003 --> blue underlined text

To get clickable links from these techniques, you may also need, under oo3 general preferences, to set:
General > Attachments > Automatically create attachments from typed URLs

--

Last edited by RobTrew; 2011-02-17 at 10:23 PM..
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
link to pdf instead of copy? nicoledb OmniOutliner 3 for Mac 3 2013-02-27 01:53 PM
Copy Magnet link URL bug Drayon OmniWeb Bug Reports 1 2013-01-11 01:42 PM
Blending features of Quick Entry and Copy As Link? korm OmniFocus Extras 0 2012-09-27 07:32 AM
Can I export/copy a formatted file to Pages? nm2 OmniOutliner for iPad 5 2011-05-12 02:33 PM
Copy as Link to project not working after a Sync mlevin777 OmniFocus 1 for Mac 4 2011-03-09 04:23 PM


All times are GMT -8. The time now is 10:37 AM.


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