Not sure what I’m doing wrong.
I need to set context, or set a new context using AppleScript.
Thanks for any help.
tell application "OmniFocus"
tell front document
tell content of document window 1
set SelectedTasks to value of every selected tree
if ((count of SelectedTasks) < 1) then
display alert "You must first select an item to complete." as warning
return
end if
repeat with anItem in SelectedTasks
set context of anItem to "Waiting"
end repeat
end tell
end tell
end tell
The problem is this: context is a property of the task class. Its class is context.
So you need to store a reference to the context element in a variable first.
Tell me if you have any more doubts.
Code:
property context_name : "Waiting"
tell application "OmniFocus"
tell front document
-- GET CONTEXT
set lst_contexts to every flattened context whose (name = context_name)
tell content of document window 1
set SelectedTasks to value of every selected tree
if ((count of SelectedTasks) < 1) then
display alert "You must first select an item to complete." as warning
return
end if
end tell
if (length of lst_contexts) > 0 then
set the_context to (item 1 of lst_contexts)
else
-- CONTEXT NOT EXISTS; CREATE CONTEXT
set the_context to (make new context with properties {name:context_name})
end if
repeat with anItem in SelectedTasks
set context of anItem to the_context
end repeat
end tell
end tell