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

 
Applescript to capture list of actions to clipboard Thread Tools Search this Thread Display Modes
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

Last edited by RobTrew; 2011-03-25 at 06:16 AM.. Reason: Ver 0.6 Uses Growl to report result
 
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.
 
Quote:
Originally Posted by JohnJ80 View Post
I think it's an Apple bug.
Turns out I had pasted a comment into the CSS string at the last moment.

Amended above, and should work now.
 
Quote:
Originally Posted by RobTrew View Post
Turns out I had pasted a comment into the CSS string at the last moment.

Amended above, and should work now.
Yep. Works great - thanks!

J.
 
How can you get this to work so it includes the Notes assigned to a Task?
 
Quote:
Originally Posted by policarpo View Post
How can you get this to work so it includes the Notes assigned to a Task?
I have amended the code in post 11 above to include line 3:
Code:
property pblnIncludeNotes : false
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).

--

Last edited by RobTrew; 2010-12-12 at 04:49 AM..
 
Quote:
Originally Posted by RobTrew View Post
I have amended the code in post 11 above to include line 3:
Code:
property pblnIncludeNotes : false
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).

--
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.
 
Ver 0.6 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 Growl, if installed, to report success.

--

Last edited by RobTrew; 2011-03-25 at 06:20 AM..
 
Quote:
Originally Posted by RobTrew View Post
Ver 0.6 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 Growl, if installed, to report success.

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

J.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pausing some actions under a single actions list pauses the whole single actions list zdlo OmniFocus 1 for Mac 6 2012-08-27 09:08 PM
Applescript to Save Clipboard to Clippings? jamespro OmniOutliner 3 for Mac 0 2011-03-23 11:11 AM
Applescript to Paste from Clipboard richgoidel OmniFocus Extras 2 2010-12-13 03:00 PM
Copy Actions and/or Projects to Clipboard carlsson OmniFocus 1 for Mac 3 2010-05-31 12:27 AM
Using iSight/Mic to capture actions cez1 OmniFocus 1 for Mac 1 2009-04-30 02:59 PM


All times are GMT -8. The time now is 04:33 PM.


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