Triggering an Omnifocus 3 task with a script in Hazel

Can anyone please help.

Rose created an Applescript for me that would add a task in Omnifocus to pay someone in 30 days. This is triggered by the invoice being dropped into a certain folder. It works great! However I am now using the beta of OF3 on the mac.

How can I modify the following script so that rather than applying a context, it uses up to 3 tags?

THANK YOU!

Script -

set theDate to (current date) + (30 * days)

set fileName to item 1 of inputAttributes

tell application "OmniFocus 2"

tell front document

set theContext to first flattened tag where its name = "My Studio"

set theProject to first flattened project where its name = "SL Invoices to pay"

tell theProject to make new task with properties {name:("Pay " & fileName), defer date:{theDate}, deprecated context:theContext}

end tell

end tell

I just figured this out the other day. First you have to create the tags in Omnifocus. Assuming they exist, you then tell the project to create a new task with a single primary tag. Then you add each tag to the task. It looks like the following code:

set theDate to (current date) + (30 * days)
set fileName to item 1 of inputAttributes
tell application "OmniFocus"
	tell front document
		set thePrimaryTag to first flattened tag where its name = "My Studio"
		set theTagList to {first tag where its name = "Tag1", first tag where its name = "Tag2", first tag where its name = "Tag3"}
		set theProject to first flattened project where its name = "SL Invoices to pay"
		tell theProject
			set theTask to make new task with properties {name:("Pay " & fileName), defer date:theDate, primary tag:thePrimaryTag}
			repeat with theTag in theTagList
				add theTag to tags of theTask
			end repeat
		end tell
	end tell
end tell
1 Like

Just wanted to say that 2 months on this post is still creating value - you fixed a problem for me :smiley:

1 Like

Wonderful. I am happy that my code was useful.