The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Applescript to capture list of actions to clipboard (http://forums.omnigroup.com/showthread.php?t=19326)

RobTrew 2010-12-10 08:38 AM

This, however, is a version which places formatted RTF rather than plain text in the clipboard.

You can edit the CSS lines near the beginning to alter the details of point size, font, and color.

[CODE]property pTitle : "Selected actions to RTF clipboard"
property pVer : "0.6"

-- Uses table format to align labels and allow wrapping of note.

property pblnIncludeNotes : true

property pTaskLabel : "Action Item:"
property pDueLabel : "Due by:"
property pProjLabel : "Project:"
property pContextLabel : "Who:" -- or "Context: " edit as required
property pNoteLabel : "Note:"

-- edit font, point size, color, margins etc as required:
property pstrCSS : "
.TaskLabel {color:#617794;}
.DueLabel {color:#617794;}
.ProjectLabel {color:#617794;}
.ContextLabel {color:#617794;}
.NoteLabel {color:#617794; }

.Task {color:#3c6ba9; font-weight: bold;}
.Due {color:#3c6ba9;}
.Project {color:#3c6ba9;}
.Context {color:#ff0000;}
.Note {color: #666666}

td {font: 14.0px 'Lucida Grande';}
"

tell application id "com.omnigroup.omnifocus"
set oDoc to front document
tell content of front document window of oDoc
set lstActions to value of (selected trees where class of value is task or class of value is inbox task)
set lngActions to count of lstActions
if lngActions < 1 then
tell application id "com.apple.systemevents"
activate
display dialog "Select one or more (non-inbox) actions and run this script" buttons {"OK"} default button "OK" with title pTitle
end tell
return
end if
set str to ""
repeat with oAction in lstActions
set {strName, dteDue, oProject, oContext, strNote} to {name, due date, containing project, its context, note} of oAction
set str to str & "<table border=\"0\" cellpadding=\"2\">"
set str to str & "<tr><td WIDTH=100 align=\"right\" style=\"vertical-align:top\"><span class=\"TaskLabel\">" & ¬
pTaskLabel & "</span></td><td WIDTH=500><span class=\"Task\">" & strName & "</span></td></tr>"
if dteDue is not missing value then set str to ¬
(str & "<tr><td align=\"right\" style=\"vertical-align:top\"><span class=\"DueLabel\">" & pDueLabel & ¬
"</span></td><td><span class=\"Due\">" & dteDue as string) & "</span></td></tr>"
if oProject is not missing value then set str to ¬
str & "<tr><td align=\"right\" style=\"vertical-align:top\"><span class=\"ProjectLabel\">" & ¬
pProjLabel & "</span></td><td><span class=\"Project\">" & name of oProject & "</span></td></tr>"
if oContext is not missing value then
set str to ¬
str & "<tr><td align=\"right\" style=\"vertical-align:top\"><span class=\"ContextLabel\">" & pContextLabel & ¬
"</span></td><td><span class=\"Context\">" & name of oContext & "</span></td></tr>"
else
set lstContexts to name of (flattened contexts of oDoc)
tell application id "com.apple.systemevents" -- (needed for interactivity when launched by osascript, Keyboard Maestro etc)
activate
set varChoice to choose from list lstContexts with prompt ¬
"Assign a context to:" & return & return & strName ¬
default items {first item of lstContexts} ¬
cancel button name "No context needed" with title pTitle
end tell
if varChoice is not false then
set strContext to first item of varChoice
set context of oAction to (first flattened context of oDoc where name = strContext)
set str to str & "<tr><td align=\"right\" style=\"vertical-align:top\"><span class=\"ContextLabel\">" & pContextLabel & ¬
"</span></td><td><span class=\"Context\">" & strContext & "</span></td></tr>"
end if
end if
if pblnIncludeNotes then if length of strNote > 0 then ¬
set str to str & "<tr><td align=\"right\" style=\"vertical-align:top\"><span class=\"NoteLabel\">" & ¬
pNoteLabel & "</span></td><td><span class=\"Note\">" & strNote
set str to str & "</td></tr></table>"
set str to str & "<p><p>"

end repeat
end tell
end tell

set strPara to "<p>" & str & "</p>"

set strHTML to "
<html><head><style type=\"text/css\">
" & pstrCSS & "
</style></head><body>" & strPara & "</body></html>"

if length of str > 0 then
do shell script "echo " & quoted form of strHTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
set str to do shell script "echo " & quoted form of strHTML & " | textutil -format html -convert txt -stdin -stdout"
my Growl(lngActions)
end if


-- Replace a sub string
on replaceString(theText, oldString, newString)
set AppleScript's text item delimiters to oldString
set tempList to every text item of theText
set AppleScript's text item delimiters to newString
set theText to the tempList as string
set AppleScript's text item delimiters to ""
return theText
end replaceString

on Growl(lngActions)
-- If Growl is running, report the references sent

if lngActions > 0 then
if lngActions = 1 then
set strRefInflection to " action"
else
set strRefInflection to " actions"
end if
set strReport to "Formatted versions of " & (lngActions as string) & strRefInflection & " in RTF clipboard."
tell application "System Events"
set blnGrowlRunning to (count of (every process whose name is "GrowlHelperApp")) > 0
if blnGrowlRunning then
-- set strReport to text 1 thru ((length of strReport) - 2) of strReport

tell application "GrowlHelperApp"
register as application "RobTrew scripts" all notifications {"Actions handled"} default notifications {"Actions handled"} icon of application "OmniFocus"
notify with name "Actions handled" title "Actions processed" application name "RobTrew scripts" description strReport
end tell
else
activate
display dialog strReport buttons {"OK"} default button "OK" with title pTitle
end if
end tell
end if
end Growl
[/CODE]

JohnJ80 2010-12-10 09:47 AM

I think it's an Apple bug.

If i use the font selection stuff, it comes out with a small font in Times regardless of the font name or size specified. If I go back to the previous version with no effort at formatting, it comes out with a different font (small version of lucida grande).

but thanks for figuring that out.

J.

RobTrew 2010-12-10 10:36 AM

[QUOTE=JohnJ80;90255]I think it's an Apple bug.[/QUOTE]

Turns out I had pasted a comment into the CSS string at the last moment.

Amended above, and should work now.

JohnJ80 2010-12-10 02:03 PM

[QUOTE=RobTrew;90258]Turns out I had pasted a comment into the CSS string at the last moment.

Amended above, and should work now.[/QUOTE]

Yep. Works great - thanks!

J.

policarpo 2010-12-11 08:27 PM

How can you get this to work so it includes the Notes assigned to a Task?

RobTrew 2010-12-12 01:45 AM

[QUOTE=policarpo;90321]How can you get this to work so it includes the Notes assigned to a Task?[/QUOTE]

I have amended the code in [URL="http://forums.omnigroup.com/showpost.php?p=90254&postcount=11"]post 11[/URL] above to include line 3:
[CODE]property pblnIncludeNotes : false[/CODE]

if you edit 'false' to 'true' any notes attached to the selected items will also be placed in the clipboard.

(I have also updated the code to allow more flexible formatting - you can edit the CSS to get the font, color, size and margins you want for each label and data component).

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

JohnJ80 2010-12-12 06:28 PM

[QUOTE=RobTrew;90323]I have amended the code in [URL="http://forums.omnigroup.com/showpost.php?p=90254&postcount=11"]post 11[/URL] above to include line 3:
[CODE]property pblnIncludeNotes : false[/CODE]

if you edit 'false' to 'true' any notes attached to the selected items will also be placed in the clipboard.

(I have also updated the code to allow more flexible formatting - you can edit the CSS to get the font, color, size and margins you want for each label and data component).

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

Very nice, Rob. thanks for doing this. EXACTLY what I was looking for. Great feature added through applescript. Really, this would be very nice if added to OF in a future revision.

J.

marco.onderstal 2011-03-25 03:01 AM

Thank very much
 
This was exact the thing I was looking for

Regards

RobTrew 2011-03-25 05:59 AM

[URL="http://forums.omnigroup.com/showpost.php?p=90254&postcount=11"]Ver 0.6[/URL] in post 11 above contains some improvements in dialog behaviour - (focus, default button) mainly noticeable when using the script from LaunchBar, Keyboard Maestro etc.

Also adds use of [URL="http://growl.info/"]Growl[/URL], if installed, to report success.

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

JohnJ80 2011-03-25 06:57 AM

[QUOTE=RobTrew;95159][URL="http://forums.omnigroup.com/showpost.php?p=90254&postcount=11"]Ver 0.6[/URL] in post 11 above contains some improvements in dialog behaviour - (focus, default button) mainly noticeable when using the script from LaunchBar, Keyboard Maestro etc.

Also adds use of [URL="http://growl.info/"]Growl[/URL], if installed, to report success.

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

Any way to preserve the formatting in the notes? I.e. returns, links, etc...

J.


All times are GMT -8. The time now is 03:39 PM.

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