Run AppleScript independent of matched files?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I have Hazel watching the folder in which my OmniFocus database sits. Whenever the "OmniFocus.ofocus" file "did change" - meaning I made a change in my OmniFocus app - I have Hazel run an AppleScript.

The AppleScript works on its own. And, Hazel notices when "OmniFocus.ofocus" changes. But, Hazel wants to process the files in this folder against the AppleScript. The AppleScript has nothing to do with processing files. It runs against my calendar. But, I want this script run against my calendar each time my "OmniFocus.ofocus" file changes.

How can I have Hazel ignore the files after matching and just run the AppleScript?
johncatalano
 
Posts: 10
Joined: Sat Mar 22, 2014 9:58 am

Hazel operates by matching files and operating on it. It will pass the file in to the script but it's up to the script to do anything with it. Your script is more than free to ignore it.
Mr_Noodle
Site Admin
 
Posts: 11870
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

The script runs fine by itself. It is pasted, below.
When I link the script, Hazel throws errors via Notification Center and then the script is not run.
When I embed the script, Hazel complains it expected "end" but found "property". See screenshot.

The log shows this error:
}
2020-05-01 15:40:10.203 hazelworker[58954] OmniFocus.ofocus: Rule OmniFocus to Calendar app matched.
2020-05-01 15:40:10.205 hazelworker[58954] [Error] AppleScript failed: Error executing AppleScript on file /Users/johncatalano/Library/Containers/com.omnigroup.OmniFocus3/Data/Library/Application Support/OmniFocus/OmniFocus.ofocus.
2020-05-01 15:40:10.205 hazelworker[58954] OSAScript error: {
OSAScriptErrorNumberKey = "-1708";
}

What do I need to include in my script so that Hazel runs it without throwing errors?

[img]
https://imgur.com/wHat9r0
[/img]

Code: Select all
property calendar_name : "OmniFocus" -- This is the name of your calendar
property default_duration : 0 --minutes

-- Rosemary Orchard
-- Modified from a script by unlocked2412
-- This creates calendar events for tasks which have a due date, if an estimated time is not set then the task defaults to 30 minutes in length

tell application "Calendar"
   set calendar_element to calendar calendar_name
   tell calendar calendar_name
      set theEvents to every event
      repeat with current_event in theEvents
         delete current_event
      end repeat
   end tell
end tell

tell application "OmniFocus"
   tell default document
      set task_elements to flattened tasks whose ¬
         (completed is false) and (due date ≠ missing value)
      repeat with item_ref in task_elements
         -- GET OMNIFOCUS TASKS
         set the_task to contents of item_ref
         set task_name to name of the_task
         set task_note to note of the_task
         set task_due to due date of the_task
         set task_estimate to estimated minutes of the_task
         set task_url to "omnifocus:///task/" & id of the_task
         if task_estimate is missing value then set task_estimate to default_duration
         -- BUILD CALENDAR DATE
         set end_date to task_due
         set start_date to task_due - (task_estimate * minutes)
         -- CREATE CALENDAR EVENT
         tell application "Calendar"
            tell calendar_element
               if not (exists (first event whose (start date = start_date) and (summary = task_name))) then
                  make new event with properties ¬
                     {summary:task_name, start date:start_date, end date:end_date, url:task_url} at calendar_element
               end if
            end tell
         end tell
      end repeat
   end tell
end tell
johncatalano
 
Posts: 10
Joined: Sat Mar 22, 2014 9:58 am

I fixed the errors by removing these property values at the top of my script and just hard-coding them.

property calendar_name : "OmniFocus" -- This is the name of your calendar
property default_duration : 0 --minutes
johncatalano
 
Posts: 10
Joined: Sat Mar 22, 2014 9:58 am


Return to Support