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 Show Active Tasks Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
This script reports "active" tasks, defined as those that are flagged and not completed. The output format is as

HEADER (COUNT)
BAR
PRE-STRING context SEPARATER task
...

Action groups can be displayed expanded or not, whereby in the latter case they show as

Project Group SEPARATER group name <COUNT>

Tasks with empty contexts show as

PRE-STRING <empty> SEPARATER task

The report can be sorted forward or reverse, and counts can be hidden. I use this with GeekTool -- caveat OF must be running for it to work. The script is attached in an archive.

Code:
(*
	This script creates a list of flagged actions and reports them in (reverse) order by context
	
	Report Format		
		NOHEADER
			or
		HEADER (COUNT)
		BAR
		PRESTRING context SEPARATOR task
		...
*)

property reverseSort : "true" -- set to false for forward sort
property showCount : "true" -- set to false to avoid showing count
property expandGroup : "true" -- set to true to expand action groups
property headerStr : "Active" -- HEADER text when active count > 0
property nheaderStr : "No Active Tasks" -- NOHEADER when active count = 0
property mtcntxtStr : "<empty>" -- string when context is missing
property barStr : "--" -- BAR string after header
property preStr : "●" & tab -- PRESTRING prior to each list item
property actGroupStr : "Project Group" -- pre-string when task is action group (shows when expandGroup = false)
property sepStr : " : " -- SEPARATOR string between context and task

tell application "OmniFocus"
	tell front document
		-- get list of active tasks
		set AList to flattened tasks where ((flagged is true) and (completed is false))
		if ((count of AList) > 0) then
			-- make the header
			set theCount to (count of AList)
			set SortedList to ""
			set theReport to ""
			-- start parsing each task
			repeat with ListItem in AList
				if (the number of tasks of ListItem = 0) then
					-- a single task
					try
						set theContext to preStr & (name of context of ListItem) & sepStr
					on error
						set theContext to preStr & mtcntxStr & sepStr
					end try
					set theAction to (name of ListItem)
					set SortedList to SortedList & (theContext & theAction) as list
				else
					-- an action group (no expand or expand)
					if (expandGroup is "false") then
						-- do not expand action groups
						if (showCount is "true") then
							set countStr to " <" & (number of tasks of ListItem) & ">"
						else
							set countStr to ""
						end if
						set theContext to preStr & actGroupStr & sepStr
						set theAction to (name of containing project of ListItem) & sepStr & (name of ListItem) & countStr
						set SortedList to SortedList & (theContext & theAction) as list
					else
						-- expand action groups completely
						set XList to ((flattened tasks of ListItem) where (completed is false))
						set theCount to theCount - 1
						repeat with XListItem in XList
							try
								set theContext to preStr & (name of context of XListItem) & sepStr
							on error
								set theContext to preStr & mtcntxtStr & sepStr
							end try
							set theAction to (name of XListItem)
							set theCount to theCount + 1
							set SortedList to SortedList & (theContext & theAction) as list
						end repeat
					end if
				end if
			end repeat
			if (reverseSort is "true") then
				set SortedList to the reverse of my simple_sort(the SortedList)
			else
				set SortedList to my simple_sort(the SortedList)
			end if
			repeat with ListItem in SortedList
				set theReport to theReport & (ListItem) & return
			end repeat
		else
			set theReport to nheaderStr
		end if
	end tell
	if (showCount is "true") then
		set countStr to " (" & theCount & ")"
	else
		set countStr to ""
	end if
	set theReport to headerStr & countStr & return & barStr & return & theReport
	return theReport
end tell

on simple_sort(my_list)
	set the index_list to {}
	set the sorted_list to {}
	repeat (the number of items in my_list) times
		set the low_item to ""
		repeat with i from 1 to (number of items in my_list)
			if i is not in the index_list then
				set this_item to item i of my_list as text
				if the low_item is "" then
					set the low_item to this_item
					set the low_item_index to i
				else if this_item comes before the low_item then
					set the low_item to this_item
					set the low_item_index to i
				end if
			end if
		end repeat
		set the end of sorted_list to the low_item
		set the end of the index_list to the low_item_index
	end repeat
	return the sorted_list
end simple_sort
Attached Files
File Type: zip ShowActiveTasks.zip (10.7 KB, 675 views)
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show active and on hold projects with script? mrubenson OmniFocus Extras 3 2012-01-04 11:01 AM
Perspective of Active Tasks ScottA83 OmniFocus 1 for Mac 1 2009-11-02 07:49 AM
Applescript to export each active project to a separate CSV signal15 OmniFocus Extras 0 2009-08-05 11:52 AM
Is there a way to hide active projects with no tasks? CatOne OmniFocus 1 for Mac 4 2009-07-20 03:37 PM
AppleScript: Set Active Workspace dennisffm OmniWeb General 3 2008-03-23 12:18 PM


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


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