Hi,
I’m trying to create a workflow with Hazel and OF. Hazel read file tags and then creates a task on OF existing projects (all based on files tags) and also attach the file to task.
I’ve search for applescripts to run on Hazel but I always get the same error “Error on running Applescript on file…”
The script I’m using was found in this forum. I’ve analysed Hazel logs and It seems the problem maybe related to definition of the variables “Context” and “Project”. It seems don’t know how to get them…
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
Thanks for the help.
The script returns the same error outside Hazel. but I’ve isolated the error It’s on tag…
<set theTask tomaketask with properties {name:theTask, tag :theTag}>
full code (run outside Hazel):
tellapplication “Finder”
set filePath to (POSIX path of (target offrontwindowasalias))
set theFile tothe selection asalias
set fileName to (name of theFile)
set {name:fileName, name extension:nameExtension} to theFile
set fileName totext 1 thru ((getoffset of “.” & nameExtension in fileName) - 1) of fileName
set theDate tocurrent date
set theTask to “Review «” & fileName & “»”
set theNote to return & return & "Imported by Hazel on " & (theDate asstring) & "
"
endtell
tellapplication “OmniFocus”
tellfrontdocument
set theTag tofirstflattened tagwhereits name = “Review”
set theProject tofirstflattened projectwhereits name = “ToDo”
tell theProject
set theTask tomaketask with properties {name:theTask, tag :theTag}
set note of theTask to theNote
tellthe note of theTask
make new file attachment with properties {file name:theFile, embedded:false}
tell application “Finder”
set filePath to (POSIX path of (target of front window as alias))
set theFile to the selection as alias
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 “Review «” & fileName & “»”
set theNote to return & return & "Imported by Hazel on " & (theDate as string) & "
"
end tell
tell application “OmniFocus”
tell front document
set theTag to first flattened tag where its name = “Review”
set theProject to first flattened project where its name = “ToDo”
tell theProject
set theTask to make task with properties {name:theTask, tag :theTag}
set note of theTask to theNote
tell the note of theTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
end tell
end tell
end tell
tell application "Finder"
set filePath to (POSIX path of (target of front window as alias))
set theFile to the selection as alias
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 "Review «" & fileName & "»"
set theNote to return & return & "Imported by Hazel on " & (theDate as string) & "
"
end tell
tell application "OmniFocus"
tell front document
set theTag to first flattened tag where its name = "Review"
set theProject to first flattened project where its name = "ToDo"
tell theProject
set theTask to make task with properties {name:theTask}
set note of theTask to theNote
tell the note of theTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
add theTag to end of tags of theTask
return theTask
end tell
end tell
end tell