Using hazel to assign task to existing project

I’ve searched the forums and didn’t find the answer.
I was able to add task to Omni Focus2 inbox by hazel automatically after downloading pdf , but i’d like to know the apple script to assign those task to an existing project depending on their names.

The apple script I’m currently using is


tell application "Finder" to set file_name to (name of theFile)
set theDate to current date
set theNote to "Downloaded " & (theDate as string) & " 

"
set projectname to "Test Project"

set theTask to "Review \"" & file_name & "\""

tell application "OmniFocus"
	set task_title to theTask
	tell default document
		set newTask to make new inbox task with properties {name:task_title}
		set theProject to projectname
		set note of newTask to theNote
		tell the note of newTask
			make new file attachment with properties {file name:theFile, embedded:false}
		end tell
	end tell
end tell

Thinking out loud, I believe you need to tell the Project to create the note. Here’s a script I use in Hazel to move files into a Read/Review project in OF.

tell application "Finder"
	set fileName to (name of theFile)
	set {name:fileName, name extension:nameExtension} to theFile
	set fileName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
	set theDate to current date
	set theTask to "Read «" & fileName & "»"
	set theNote to return & return & "Imported by Hazel on " & (theDate as string) & " 

"
end tell

tell application "OmniFocus"
	tell front document
		set theContext to first flattened context where its name = "Any Device"
		set theProject to first flattened project where its name = "Read/Review"
		tell theProject
			set theAction to make task with properties {name:theTask, context:theContext}
			set note of theAction to theNote
			tell the note of theAction
				make new file attachment with properties {file name:theFile, embedded:false}
			end tell
		end tell
	end tell
end tell
1 Like