View Single Post
Testing code for OFSelectAny()
version: April 8 2009 by David Amis
These tests were written for my OmniFocus document, you will need to modify the code to fit your document for some of the tests.

Code:
OFSelectTestUI()

on OFSelectTestUI() --Let the user choose a test from a list.
	local tests, testType
	
	set tests to ¬
		{"Task", "Task2", "Task by id", "Inbox task", "Group", "Project", "Project2", "Project by id", "Folder", "Inbox", "Library", "Sidebar", "list", "nothing in sidebar"}
	set testType to choose from list tests ¬
		with title "OFSelectAny tester" with prompt "Choose a type to select:" OK button name "Select" without empty selection allowed
	if class of testType is list then
		OFSelectTest(item 1 of testType)
	end if
end OFSelectTestUI


on OFSelectTest(testType) -- testing code for OFSelectAny()
	local aProject, aTask, someTasks, aFolder, taskID, projectID, aList
	
	-- document should contain at least one folder or project in the Library
	-- following test code is dependant on your OF document	
	
	if testType is "Task" then -- assumes there is a task in a root project, i.e. a misc. SAL
		tell application "OmniFocus"
			tell default document
				set aProject to first project whose status is active
				set aTask to task 1 of aProject whose completed is false
			end tell
		end tell
		OFSelectAny(aTask)
	end if
	if testType is "Task2" then
		tell application "OmniFocus"
			tell default document
				set aFolder to first folder
				set aProject to first project in aFolder whose status is active
				set aTask to task 2 of aProject whose completed is false
			end tell
		end tell
		OFSelectAny(aTask)
	end if
	if testType is "Task by id" then -- assumes there is a task in a root project, i.e. a misc. SAL
		tell application "OmniFocus"
			tell default document
				set aProject to first project whose status is active
				set aTask to task 1 of aProject whose completed is false
				set taskID to id of aTask
			end tell
		end tell
		OFSelectAny(taskID)
	end if
	if testType is "Inbox task" then
		tell application "OmniFocus"
			tell default document
				set someTasks to inbox tasks whose completed is false
				set aTask to item 1 of someTasks
			end tell
		end tell
		OFSelectAny(aTask)
	end if
	if testType is "Group" then
		tell application "OmniFocus"
			tell default document
				set aFolder to second folder
				set aProject to first project in aFolder whose status is active
				set aTask to task 6 of aProject whose completed is false -- really big assumption here
			end tell
		end tell
		OFSelectAny(aTask)
	end if
	if testType is "Project" then
		tell application "OmniFocus"
			tell default document
				set aFolder to first folder
				set aProject to first project in aFolder whose status is active
			end tell
		end tell
		OFSelectAny(aProject)
	end if
	if testType is "Project2" then
		tell application "OmniFocus"
			tell default document
				set aFolder to second folder
				set aProject to second project in aFolder whose status is active
			end tell
		end tell
		OFSelectAny(aProject)
	end if
	if testType is "Project by id" then
		tell application "OmniFocus"
			tell default document
				set aFolder to first folder
				set aProject to first project in aFolder whose status is active
				set projectID to id of aProject
			end tell
		end tell
		OFSelectAny(projectID)
	end if
	if testType is "Folder" then
		tell application "OmniFocus"
			tell default document
				set aFolder to second folder
			end tell
		end tell
		OFSelectAny(aFolder)
	end if
	if testType is "Inbox" then
		tell application "OmniFocus"
			tell default document
				tell sidebar of document window 1
					set aProject to inbox
				end tell
			end tell
		end tell
		OFSelectAny(aProject)
	end if
	if testType is "Library" then
		tell application "OmniFocus"
			tell default document
				tell sidebar of document window 1
					set aProject to library
				end tell
			end tell
		end tell
		OFSelectAny(aProject)
	end if
	if testType is "Sidebar" then
		tell application "OmniFocus"
			tell default document
				tell document window 1
					set aProject to sidebar
				end tell
			end tell
		end tell
		OFSelectAny(aProject)
	end if
	if testType is "list" then
		tell application "OmniFocus"
			tell default document
				set aFolder to second folder
				set aProject to second project in aFolder whose status is active
				set someTasks to tasks of aProject whose completed is false
				set aList to {aProject}
				set aList to aList & someTasks
			end tell
		end tell
		OFSelectAny(aList)
	end if
	if testType is "nothing in sidebar" then
		OFSelectAny({})
	end if
end OFSelectTest