View Single Post
I've made a couple of improvements, including a prompt for the grade you give yourself on a given question, and conditional formatting. Rows scored 0 to 4 in the grade column now appear in black. I'm not very good at scripting OmniOutliner, so there was a lot of trial and error involved here until I came up with something that worked. Please feel free to suggest or make changes.

Code:
tell application "OmniOutliner" -- add Professional if you have the pro version; I only have the standard version.
	-- columns:
	-- 1 is checkbox (unused)
	-- 2 is for content (questions in the row; answers as comments)
	-- 3 is quality
	-- 4 is due
	-- 5 is numReps
	-- 6 is EF	

	
	set value of cell "0-6" of selected row of front document to the text returned of (display dialog "Grade 0-6 " default answer "3")
	
	
	set the state of cell "Question?" of selected row of front document to checked
	
	set baseEaseFactor to 1.3
	set i to value of cell 5 of selected row of front document -- number of repetitions thus far
	set q to value of cell 3 of selected row of front document -- Get quality #
	-- Set existing easiness factor...
	if value of cell 6 of selected row of front document contains "" then
		set value of cell 6 of selected row of front document to baseEaseFactor as text
		set oldEF to baseEaseFactor
	else
		set oldEF to value of cell 6 of selected row of front document -- Get oldEF
	end if
	-- If there have been no reps:
	if i as integer is equal to 0 then
		set nextDue to do shell script "date -v+0d +%Y-%m-%d" as string
		set value of cell 4 of selected row of front document to nextDue as string
		set value of cell 5 of selected row of front document to "1" as string
		set value of cell 6 of selected row of front document to baseEaseFactor as string
		return
		-- If there have been 2 reps:
	else if i as integer is equal to 1 then
		set i to i + 1
		set value of cell 5 of selected row of front document to i as string
		set dueCellValue to do shell script "date -v+1d +%Y-%m-%d" as string
		set value of cell 4 of selected row of front document to dueCellValue as string
		return
	else if i as integer is equal to 2 then
		set nextDue to do shell script "date -v+6d +%Y-%m-%d" as string
		set value of cell 4 of selected row of front document to nextDue as string
		set value of cell 5 of selected row of front document to "3" as string
		set value of cell 6 of selected row of front document to baseEaseFactor as string
		return
	else -- all other numbers
		set value of cell 5 of selected row of front document to i + 1 as string
		set newEF to oldEF - 0.8 + 0.28 * q - 0.02 * q * q
		if newEF is less than 1.3 then
			set newEF to 1.3
		end if
		if newEF is greater than or equal to 2.5 then
			set newEF to 2.5
		end if
		set value of cell 6 of selected row of front document to newEF as string
		if q > 0 then
			set nextDue to (i * (i - 1) * newEF) as integer
			set dueCellValue to do shell script "date -v+" & nextDue & "d +%Y-%m-%d"
			set value of cell 4 of selected row of front document to dueCellValue as string
			set i to i + 1
			set value of cell 5 of selected row of front document to i as string
		else
			set nextDue to do shell script "date -v+0d +%Y-%m-%d" as string
			set value of cell 4 of selected row of front document to nextDue as string
			set value of cell 5 of selected row of front document to "0" as string
		end if
	end if
end tell

delay 2
-- new part to format rows graded less than 4:
tell application "OmniOutliner" -- add Professional if you have the pro version; I only have the standard version.
	tell front document
		repeat with theRow in (every row whose state of cell "Question?" is checked)
			set testCell to value of cell "0-6" of theRow
			if the testCell ≥ 4 then
				tell style of theRow
					set value of attribute "font-fill" to {0, 0, 0} -- RGB for black
				end tell
			else
				tell style of theRow
					set value of attribute "font-fill" to {55838, 634, 634} -- RGB for red
				end tell
			end if
		end repeat
	end tell
end tell