Use applescript to create a new task with a flag


I am trying to add a variable to David Sparks applescript, which creates a new task with Hazel ( )that would add a flag to the newly created task. I have been trying various options but to no avail and would appreciate some help. Thank you. Philippe

Here’s a modified version of the script you linked to that creates a flagged task by adding flagged:true to the properties of the task created:

set theDate to current date
set theTask to "Pay Life Insurance"
set theNote to "Lovingly Scanned by your Mac on " & (theDate as string)

tell application "OmniFocus"
	tell front document
		set theContext to first flattened context where its name = "Haushalt"
		set theProject to first flattened project where its name = "Routine Morgen"
		tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext, flagged:true}
	end tell
end tell

Dear Svenl, thank you very much for your help. I was close, but did not get the wording quite right. Thanks, Philippe