Omnifocus 3 script to make a new daily project with different tasks depending on day of the week

Hey!
After seeing Chadlenberg’s recent post about adding tags to a project in Omnifocus via Applescript, I thought I’d post a script I made recently. I work as a booker for various music venues in NYC, so there are many many tasks which must be completed daily. They are totally different tasks depending on the day of the week, so figuring out how to create a reusable project template for OF was a bit of a challenge. After some time tweaking things, I think I’ve got a cool script going.
I’m posting a more generic version of this script for the forum, in case anyone decided to use it for their own needs.
Heads up though, I learned (after many hours of debugging) that the tags must already be created in Omnifocus in order for this script to work, otherwise Applescript will throw an error. So in the case of this generic script, it’s necessary to make new tags first called “Work A Tag”, “Work B Tag”, “Exercise”, and “Music”.

My applescript skills are not that great, so I welcome any guidance or tips on how to make this a better script. Thanks!

-- Create Date Variables

set theDate to date string of (current date)
set theDay to weekday of (current date)
set dueDate to (current date)

-- set the time of the due date to be 11pm
tell dueDate
	set {its hours, its minutes, its seconds} to {23, 0, 0}
end tell

-- Create Task Variables

set sundayWorkA to {"Sunday WorkA task1", "Sunday WorkA task2", "Sunday WorkA task3"}
set sundayWorkB to {"Sunday WorkB task1", "Sunday WorkB task2", "Sunday WorkB task3"}

set mondayWorkA to {"Monday WorkA task1", "Monday WorkA task2", "Monday WorkA task3"}
set mondayWorkB to {"Monday WorkB task1", "Monday WorkB task2", "Monday WorkB task3"}

set tuesdayWorkA to {"Tuesday WorkA task1", "Tuesday WorkA task2", "Tuesday WorkA task3"}
set tuesdayWorkB to {"Tuesday WorkB task1", "Tuesday WorkB task2", "Tuesday WorkB task3"}

set wednesdayWorkA to {"Wednesday WorkA task1", "Wednesday WorkA task2", "Wednesday WorkA task3"}
set wednesdayWorkB to {"Wednesday WorkB task1", "Wednesday WorkB task2", "Wednesday WorkB task3"}

set thursdayWorkA to {"Thursday WorkA task1", "Thursday WorkA task2", "Thursday WorkA task3"}
set thursdayWorkB to {"Thursday WorkB task1", "Thursday WorkB task2", "Thursday WorkB task3"}

set fridayWorkA to {"Friday WorkA task1", "Friday WorkA task2", "Friday WorkA task3"}
set fridayWorkB to {"Friday WorkB task1", "Friday WorkB task2", "Friday WorkB task3"}

set saturdayWorkA to {"Saturday WorkA task1", "Saturday WorkA task2", "Saturday WorkA task3"}
set saturdayWorkB to {"Saturday WorkB task1", "Saturday WorkB task2", "Saturday WorkB task3"}


set exerciseTasks to {"Exercise at least 45 minutes"}
set musicTasks to {"Practice at least 30 minutes"}

-- Activate Omnifocus 
tell application "OmniFocus"
	activate
	tell default document
		-- Set Tag Variables
		set workATag to first flattened tag where its name is "Work A Tag"
		set workBTag to first flattened tag where its name is "Work B Tag"
		set musicTag to first flattened tag where its name is "Music"
		set exerciseTag to first flattened tag where its name is "Exercise"
		
		-- Make a new Omnifocus Document
		set theProject to make new project with properties {name:theDate, due date:dueDate}
		
		tell theProject
			
			-- Make Parent Tasks
			set workAParentTask to make new task with properties {name:"Work A", primary tag:workATag}
			set workBParentTask to make new task with properties {name:"Work B", primary tag:workBTag}
			set musicParentTask to make new task with properties {name:"Music", primary tag:musicTag}
			set exerciseParentTask to make new task with properties {name:"Exercise", primary tag:exerciseTag}
			
			-- Make Tasks Depending On Day Of Week
			if weekday of (current date) is Sunday then
				repeat with theItem in sundayWorkA
					set workATask to make new task with properties {name:theItem, primary tag:workATag}
					move workATask to end of tasks of workAParentTask
				end repeat
				repeat with theItem in sundayWorkB
					set workBTask to make new task with properties {name:theItem, primary tag:workBTag}
					move workBTask to end of tasks of workBParentTask
				end repeat
				
			else if weekday of (current date) is Monday then
				repeat with theItem in mondayWorkA
					set workATask to make new task with properties {name:theItem, primary tag:workATag}
					move workATask to end of tasks of workAParentTask
				end repeat
				repeat with theItem in mondayWorkB
					set workBTask to make new task with properties {name:theItem, primary tag:workBTag}
					move workBTask to end of tasks of workBParentTask
				end repeat
				
				
			else if weekday of (current date) is Tuesday then
				repeat with theItem in tuesdayWorkA
					set workATask to make new task with properties {name:theItem, primary tag:workATag}
					move workATask to end of tasks of workAParentTask
				end repeat
				repeat with theItem in tuesdayWorkB
					set workBTask to make new task with properties {name:theItem, primary tag:workBTag}
					move workBTask to end of tasks of workBParentTask
				end repeat
				
				
			else if weekday of (current date) is Wednesday then
				repeat with theItem in wednesdayWorkA
					set workATask to make new task with properties {name:theItem, primary tag:workATag}
					move workATask to end of tasks of workAParentTask
				end repeat
				
				repeat with theItem in wednesdayWorkB
					set workBTask to make new task with properties {name:theItem, primary tag:workBTag}
					move workBTask to end of tasks of workBParentTask
				end repeat
				
				
			else if weekday of (current date) is Thursday then
				repeat with theItem in thursdayWorkA
					set workATask to make new task with properties {name:theItem, primary tag:workATag}
					move workATask to end of tasks of workAParentTask
				end repeat
				repeat with theItem in thursdayWorkB
					set workBTask to make new task with properties {name:theItem, primary tag:workBTag}
					move workBTask to end of tasks of workBParentTask
				end repeat
				
				
			else if weekday of (current date) is Friday then
				repeat with theItem in fridayWorkA
					set workATask to make new task with properties {name:theItem, primary tag:workATag}
					move workATask to end of tasks of workAParentTask
				end repeat
				repeat with theItem in fridayWorkB
					set workBTask to make new task with properties {name:theItem, primary tag:workBTag}
					move workBTask to end of tasks of workBParentTask
				end repeat
				
				
			else if weekday of (current date) is Saturday then
				repeat with theItem in saturdayWorkA
					set workATask to make new task with properties {name:theItem, primary tag:workATag}
					move workATask to end of tasks of workAParentTask
				end repeat
				repeat with theItem in saturdayWorkB
					set workBTask to make new task with properties {name:theItem, primary tag:workBTag}
					move workBTask to end of tasks of workBParentTask
				end repeat
				
			end if
			
			repeat with theItem in exerciseTasks
				set exerciseTask to make new task with properties {name:theItem, primary tag:exerciseTag}
				move exerciseTask to end of tasks of exerciseParentTask
			end repeat
			
			
			repeat with theItem in musicTasks
				set musicTask to make new task with properties {name:theItem, primary tag:musicTag}
				move musicTask to end of tasks of musicParentTask
			end repeat
			
		end tell
	end tell
end tell
4 Likes

Thanks for sharing! You’ve inspired me to do something similar I think!

1 Like

Use the try command to use the tag if it already exists, or create it if it doesn’t:

try
  set workATag to first flattened tag where its name is "Work A Tag"
on error
  set workATag to make new tag with properties {name:"Work A Tag"}
end try

One thing I’d still like to know how to do is add more than one tag to a task. I found a tweet about there being a tags property, but this doesn’t work for me.

1 Like

Ooh, that is a hot tip! Thx!

To add more tags to a task:

try
  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
1 Like