Hazel / Omnifocus - task from file

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Hazel / Omnifocus - task from file Sat Jan 28, 2023 3:30 pm • by bsilvamm
Hi
I'm trying to use Hazel to automate task creation in Omnifocus. I've searched and found a script/Hazel rule that could be used, but unfortunately I get an error running the script. I found here the rule: https://www.macsparky.com/blog/2012/8/a ... cus-tasks/

Does anyone have some Hazel Rule that have a trigger based on file attribute tag, and create a task in OmniFocus attaching the file also?

I'm on MacOS Ventura, Omnifocus 3 and Hazel 5.2.

Bruno
bsilvamm
 
Posts: 4
Joined: Sat Jan 28, 2023 3:18 pm

Re: Hazel / Omnifocus - task from file Mon Jan 30, 2023 10:42 am • by Mr_Noodle
What is the error you are getting?
Mr_Noodle
Site Admin
 
Posts: 11174
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel / Omnifocus - task from file Mon Jan 30, 2023 10:57 am • by bsilvamm
error on running Applescript on file...
bsilvamm
 
Posts: 4
Joined: Sat Jan 28, 2023 3:18 pm

Re: Hazel / Omnifocus - task from file Tue Jan 31, 2023 10:52 am • by Mr_Noodle
Try turning on debug mode as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

After that, check the logs. Hopefully there should be more diagnostics about what's going wrong with the AppleScript.
Mr_Noodle
Site Admin
 
Posts: 11174
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel / Omnifocus - task from file Wed Feb 01, 2023 8:01 am • by bsilvamm
Thanks @ Mr_Noodle!

The error i get in log is:

If I use “create new task” I get this error:
NSLocalizedDescription = “OmniFocus got an error: AppleEvent handler failed.”;

If I use create new inbox task I get the error:
“OmniFocus got an error: Can\U2019t make or move that element into that container.”

The script is:
```
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 “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

```
bsilvamm
 
Posts: 4
Joined: Sat Jan 28, 2023 3:18 pm

Re: Hazel / Omnifocus - task from file Wed Feb 01, 2023 10:44 am • by Mr_Noodle
I suggest trying the script outside Hazel and see if you get the same errors there. If so, there's probably an issue with the script in relation to Omnifocus (maybe OF changed their AppleScript dictionary).
Mr_Noodle
Site Admin
 
Posts: 11174
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel / Omnifocus - task from file Thu Feb 02, 2023 5:01 am • by bsilvamm
Thanks for the advise. It also don't work outside Hazel.
bsilvamm
 
Posts: 4
Joined: Sat Jan 28, 2023 3:18 pm


Return to Open Discussion