The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Copy as (RTF-formatted) labelled link (http://forums.omnigroup.com/showthread.php?t=20115)

RobTrew 2011-02-12 04:47 AM

Copy as (RTF-formatted) labelled link
 
In the OmniFocus main menu,[INDENT]Edit > Copy As Link[/INDENT]is invaluable, placing a link like [I]omnifocus:///task/ft9gpCMAZSF[/I] 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
[/CODE]

Greg Jones 2011-02-12 08:43 AM

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.

RobTrew 2011-02-12 08:51 AM

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.

[COLOR="White"]--[/COLOR]

RobTrew 2011-02-12 09:03 AM

[QUOTE=Greg Jones;93172]Formatting the DEVONthink link in the note field of an OmniFocus task as the document name w/link would be sweet also.[/QUOTE]

Using [B]Edit > Copy Item Link[/B] in DT and pasting into an OF note seems to do this.

Do you have a different work-flow in mind ?

RobTrew 2011-02-12 09:06 AM

[QUOTE=Greg Jones;93172]the DEVONthink reminder script[/QUOTE]

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).

Greg Jones 2011-02-12 10:17 AM

[QUOTE=RobTrew;93175]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]

The 'Add as To Do to OmniFocus' script that ships with DEVONthink. It is in the Reminders folder in the DEVONthink script menu.

RobTrew 2011-02-12 10:41 AM

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[/CODE]

RobTrew 2011-02-17 09:05 PM

[QUOTE=RobTrew;93173]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.[/QUOTE]

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 ...[LIST=1][*]Cmd C in OF[LIST][*][B]Paste with current style[/B] in OO3 --> plain [B]unlinked[/B] text of task[*][B]Paste[/B] in 003 --> legible link[/LIST][*]Running script at start of this thread[LIST][*][B]Paste with current style[/B] in OO3 --> legible [B]link[/B] to task[*][B]Paste[/B] in 003 --> blue underlined text[/LIST][/LIST]
To get clickable links from these techniques, you may also need, under oo3 general preferences, to set:[INDENT][B]General > Attachments > Automatically create attachments from typed URLs[/B][/INDENT]

[COLOR="White"]--[/COLOR]


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

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