Hello,
I’m trying out a system of tags in Omnifocus with the days of the week (eg., “Monday” “Tuesday,” etc), and I want a script that will take all my tasks with the current day’s tag and add a “Today” tag so it shows up in Forecast. So for example, I could run the script on a Tuesday morning, and all the tasks with the “Tuesday” tag would have the “Today” tag added on.
I’m the beginnerest of beginners when it comes to Applescript, and I’ve patched this together from stuff I found online, but it doesn’t work:
tell application "OmniFocus"
activate
tell front document of application "OmniFocus"
set theDay to (do shell script "date '+%A'" as string)
set theTag to the first flattened tag where its name = theDay
repeat with theTask in theTag
set tag of theTask to "Today"
end repeat
end tell
end tell
The error I see says “OmniFocus got an error: Can’t make “Today” into type tag.” Can anyone help?
Maybe try adding ‘Today’ as a tag to something first. I’m wondering if it can only create the tag against an entry if the tag already exists / is known, within the system.
I do have the tag in my system already. I may not have it actually assigned to any tasks, so I’ll try that, but it definitely does exist as a tag.
I had a similar problem on a script I was working on, and another user on this forum suggested I try creating tags like this:
set theTag to (first flattened tag where its name is "Tag Name")
on error
set theTag to make new tag with properties {name:"Tag Name"}
end try
add theTag to tags of theTask
Hope that helps.
This was a bit more complicated than I thought, but with help from the (evidently famous) Complete and Await Reply script I got it to work:
property todayTag : "Today"
tell application "OmniFocus"
set theDay to (do shell script "date '+%A'" as string)
set strTagName to theDay
tell front document
set theTodayTagID to id of item 1 of (complete todayTag as tag)
set theTodayTag to first flattened tag whose id is theTodayTagID
set lstMatches to complete strTagName as tag
if length of lstMatches > 0 then
set recMatch to item 1 of lstMatches
set strID to id of recMatch
set oContext to tag id strID
set lstAllTasks to tasks of oContext
repeat with theTask in lstAllTasks
set primary tag of theTask to theTodayTag
end repeat
else
display dialog "Context: " & strTagName & " not found."
end if
end tell
end tell
I’m enjoying this workflow for planning my week out on Sunday, then running the workflow every day to get a nice to-do list in my Forecast view.