Help requested for Applescript in Hazel

Hi all,

I’m trying to automate adding a PDF dropped into a dropbox folder with Hazel as a task in Omnifocus, with the project “Home” and the context “Anywhere”. Both are pre-existing. The basic applescript works, but I can’t figure out how to add the project and context. Any help would be appreciated. Here is the script:

 tell application "Finder" to set file_name to (name of theFile)

set theDate to current date

set theNote to "Scanned " & (theDate as string) & " 

"

set projectname to "Read"

set theTag to "Anywhere"

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

tell application "OmniFocus"

set task_title to theTask

tell front document

set newTask to make new inbox task with properties {name:task_title, primary tag:theTag}

set theProject to projectname

set note of newTask to theNote

move newTask to end of tasks of theProject

tell the note of newTask

make new file attachment with properties {file name:theFile, embedded:true}

end tell

end tell

end tell

I found this one on the omnifocus forum, it may give you some ideas. It moves files into a read-review project in omnifocus:

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