Script to get list of tasks in Today perspective, and then to get the projects for those tasks

I have a Today perspective, which comprises of tasks. But I would like to create list of projects that these tasks are part of, and perhaps copy and display that project list in a text file or in a note in Notes.

While I know some basic programming, I do not have a good enough understanding of AppleScript :(, and am at a loss as to how to do this and a search in the forums did not yield anything close.

Thanks for your help.

(On a side note: it is the ownership structure of app > document > window > content that throws me off and then which command can apply where etc. I wonder if there is a better way to understand the dictionary associated with Omnifocus. For example there is a Standard Suite and Omnifocus Suite - may be this is a question I should ask separately.)

So I think I have a script that can give me selected items from the front window.

tell application "OmniFocus"
tell front document
	tell document window 1
		# return perspective name
		set listProjects to {}
		tell content
			set theSelectedItems to value of every tree
			repeat with anItem in theSelectedItems
				set itemProject to containing project of anItem
				if itemProject is not missing value then
					set projectName to name of itemProject
				end if
				copy projectName to end of listProjects
			end repeat
		end tell
	end tell
end tell
end tell

return listProjects

Ideal would be if this can be done without the perspective open in a window.

Anyhow, for now I have a sort of solution.

1 Like