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
I wrote this to be able to make a list of action items that I can then paste into an email, a document, etc... The way I use this is to use OF to take meeting action items then I can select them all in OF, run this script, and the information is transferred to the clipboard. I can then paste them into an email, into a text file, into a word processor etc....

Use it if it's useful. No claims made on accuracy, effectiveness or the safety of your data. It's just written so no claim on being bug free:


tell front document of application "OmniFocus"
-- get the window the user is using
set |w| to first document window whose index is 1
-- find out where we are and if there's anything we can do

set theItems to selected trees of content of |w|

-- Detect common failure modes and explain

if ((count of theItems) is 0) then
display alert ¬
"Select an action to " & toolName message "You have not selected an action"
return
end if

(*) if ((count of theItems) is greater than 1) then
display alert ¬
"Select just one action to " & toolName message "You have selected more than one item, please select just one"
return
end if *)

set _body to "" -- null out text
repeat with cnt from 1 to (count of theItems)

set selectedItem to value of item cnt of theItems

if ((class of selectedItem) is inbox task) then
display alert ¬
"Sorry, action not supported" message "Actions in inbox do not reveal their projects in version " & toolVersion & " of " & toolName
return
end if


if ((class of selectedItem) is not task) then
display alert ¬
"Select an action to " & toolName message "You have selected something that isn't an action"
return
end if

try
set _dueDate to (get due date of selectedItem as date)
on error
set _dueDate to "None"

(* set _dueDate to text returned of (display dialog "Please enter data and time xx/xx/xxxx xx:xx AM/PM." default answer (current date) as string)
set _dueDate to _dueDate as date *)
end try


try
set _note to (get note of selectedItem)
on error
set _note to ""
end try


try
set _project to the name of (get containing project of selectedItem)
on error
set _project to "None"
end try

try
set _context to the name of (get context of selectedItem)
on error
set _contect to "None"
end try


try
set _subject to the name of selectedItem
on error
set _subect to "No Subject"
end try

set _body to _body & "Action Item: " & _subject & space & return
set _body to _body & "Due by: " & _dueDate & return
set _body to _body & "Project: " & _project & return
set _body to _body & "Who: " & _context & return & return



end repeat
end tell

set the clipboard to _body
 
Thanks, nice idea.

You may need to define your toolName variable, and decide what will happen if no Context is assigned.

An abbreviation might look something like:
Code:
tell application id "com.omnigroup.omnifocus"
	tell content of front document window of front document
		set lstActions to value of (selected trees where class of value is task)
		set str to ""
		repeat with oAction in lstActions
			tell oAction
				set {strName, dteDue, oProject, oContext} to {name, due date, containing project, its context}
				set str to str & "Action Item: " & strName & return
				if dteDue is not missing value then set str to (str & "Due by: " & dteDue as string) & return
				if oProject is not missing value then set str to str & "Project: " & name of oProject & return
				if oContext is not missing value then set str to str & "Who: " & name of oContext & return
				set str to str & return
			end tell
		end repeat
	end tell
end tell
if length of str > 0 then set the clipboard to str
(You have probably noticed that there is also an OmniFocus Extras forum, on which most scripts tend to be posted).

--
 
Thanks for posting this, Johnj80!
 
Quote:
Originally Posted by RobTrew View Post
Thanks, nice idea.

You may need to define your toolName variable, and decide what will happen if no Context is assigned.

An abbreviation might look something like:
Code:
tell application id "com.omnigroup.omnifocus"
	tell content of front document window of front document
		set lstActions to value of (selected trees where class of value is task)
		set str to ""
		repeat with oAction in lstActions
			tell oAction
				set {strName, dteDue, oProject, oContext} to {name, due date, containing project, its context}
				set str to str & "Action Item: " & strName & return
				if dteDue is not missing value then set str to (str & "Due by: " & dteDue as string) & return
				if oProject is not missing value then set str to str & "Project: " & name of oProject & return
				if oContext is not missing value then set str to str & "Who: " & name of oContext & return
				set str to str & return
			end tell
		end repeat
	end tell
end tell
if length of str > 0 then set the clipboard to str
(You have probably noticed that there is also an OmniFocus Extras forum, on which most scripts tend to be posted).

--
Whatever. Works for me. It'll just fail with an applescript error and I'll just add the context which it should have anyhow.

J.
 
Quote:
Originally Posted by JohnJ80 View Post
It'll just fail with an applescript error and I'll just add the context which it should have anyhow.
Yes - a pity to discard information. In case anyone finds it useful, here is a variant which will prompt the user to supply the missing context (by optionally choosing it from a list).

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:17 AM.. Reason: Ver 0.6 Uses Growl
 
Looks good. I'll give it a try. Thanks for the mods.

J.
 
I like it! Nicely done.

You wouldn't know how to set the style for the text in mail.app through applescript, would you?

J
 
Quote:
Originally Posted by JohnJ80 View Post
set the style for the text in mail.app through applescript
What in particular would you like to do ?
 
I believe that Mail has a build in style called "Normal Email". I'd like to be able to put the text in that style into the email if possible.

j.
 
I may well be missing something - haven't tried to drive Mail formatting before - but a quick glance at the Mail applescript library doesn't immediately reveal a way of setting styles through formatting.
 
 


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 05:40 PM.


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