Parsing the file name for naming the task

Hi there,

I’m trying to capture the file name of a recently imported pdf and use it as the title of the task for a new task in OF2. I was wondering if this possible?

To do this I have created a rule in Hazel which looks in a folder for pdf’s that were added today. When Hazel finds files that satisfy these requirements it runs the following AppleScript:

set theTask to file name

tell application "OmniFocus"
	tell front document
		set theContext to first flattened context where its name = "EndNote"
		set theProject to first flattened project where its name = "Kim's publication"
		tell theProject
			set theAction to make task with properties {name:theTask, context:theContext}
		end tell
	end tell
end tell

When the rule runs I get the following error message 'AppleScript Failed. Error executing AppleScript on file … '.

I was wondering if anyone could let me know where I might be going wrong?

Thank you, in advance, for your help!

Cheers

Aaron