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