View Single Post
Selecting a task and running a script like this, for example, should allow you to set Due Date intervals.

(An unusual blind patch in the Applescript library puts Start Date intervals beyond the reach of script, alas ... combining this with the breaking of repetition dialogs by localisations, repetition does look a bit neglected and in need of repair at the moment ...)

Code:
property pTitle : "Set repetition interval"
property pstrDefault : "unit:week, fixed:true, steps:1"
property pNoRepn : "No repetition"

tell application id "OFOC"
	tell front document window of front document
		set lstTasks to value of (selected trees of content where class of its value is task or class of its value is inbox task)
		if (count of lstTasks) < 1 then return
		tell first item of lstTasks
			set strName to name
			tell repetition
				set strLegend to "unit: day | week | month | year

fixed:true = repeat every N units
fixed:false = repeat N units after completion

"
				if it is not missing value then
					tell it as record
						set {blnFixed, lngSteps, eUnit} to {fixed, steps, unit}
					end tell
					set strUnit to eUnit as string
					
					
					set strLegend to "unit: day | week | month | year

fixed:true = repeat every N units
fixed:false = repeat N units after completion

"
					set strLegend to strLegend & my Translate(blnFixed, lngSteps, strUnit)
					
					set strCode to (("unit:" & strUnit & ", fixed:" & blnFixed as string) & ", steps:" & lngSteps as string)
					
					
				else
					set strCode to pstrDefault
					set strLegend to strLegend & "
Not repeating.
					
Enter a repetition string:"
				end if
				
				
				set blnParsed to false
				repeat while not blnParsed
					set varResponse to (display dialog strLegend default answer strCode buttons {"Cancel", pNoRepn, "OK"} 
						cancel button "Cancel" default button "OK" with title pTitle)
					if button returned of varResponse = pNoRepn then
						set strCode to "missing value"
					else
						set strCode to text returned of varResponse
						set strCode to do shell script "echo " & quoted form of strCode & " | perl -pe 's/(day|week|month|year)s/\\1/'"
					end if
					
					try
						set recRep to run script "tell application id \"OFOC\"
				{" & strCode & "}
				end tell"
						set blnParsed to true
					on error strMsg
						set strLegend to strMsg & "
						
						
The interval should be of the form:

" & pstrDefault
					end try
				end repeat
			end tell
			try
				set repetition to recRep
				tell repetition as record
					set {blnFixed, lngSteps, eUnit} to {fixed, steps, unit}
				end tell
				set strUnit to eUnit as string
				display alert my Translate(blnFixed, lngSteps, strUnit) message "(" & strName & ")"
			on error
				set repetition to missing value
				display alert "Not repeating" message "(" & strName & ")"
			end try
		end tell
	end tell
end tell


on Translate(blnFixed, lngSteps, strUnit)
	set strPlural to "s"
	if lngSteps = 1 then set strPlural to ""
	set strPeriod to (lngSteps as string) & space & strUnit & strPlural
	
	if blnFixed then
		"Repeating every " & strPeriod
	else
		"Repeating " & strPeriod & " after completion"
	end if
end Translate

Last edited by RobTrew; 2011-04-11 at 12:25 PM.. Reason: updated code to add a "no repetition" button