Skip to content

Instantly share code, notes, and snippets.

@Zettt
Last active February 19, 2019 04:25
Show Gist options
  • Save Zettt/1401813 to your computer and use it in GitHub Desktop.
Save Zettt/1401813 to your computer and use it in GitHub Desktop.
Day Projects for OmniFocus
-- Day Projects
--
-- Created by Zettt on 2011-11-28
-- Mac OS X Screencasts.
--
-- This script creates "Day Projects" in OmniFocus.
--
-- I use these "Day Projects" to put stuff, that I need to
-- do on a specific day, but aren't big enough to be their own project.
-- Things like "Call the doctor on Wednesday" or
-- "Check out the new store on Thursday" go in these.
-- You get the idea.
--
-- Note: I like dates being DD.MM.YYYY.
-- Leading zeros, no month names, four digit years.
-- In case you want to modify the names,
-- `man date` is your friend.
--
-- 1.0: Initial release
-- 1.1: Added value `start` so you get calendar sync and
-- alarm sounds on iOS
-- 1.2: Cleaner start time (now uses a string, e.g. "10:00:00")
-- Added hint for shorter version.
-- 1.3: Now you can set your work week to 5, 6 or 7 days.
-- 1.4: Converted all projects to single action lists
-- 1.5: - Sets a due date for all projects to same day of projects
-- This is better for my [Priorities](http://mosx.tumblr.com/post/56776970361) workflow.
-- [Screenshot of my Priorities perspective.](http://cl.ly/image/292P051A1w3U)
-- 1.6: - Replaced old "do shell script" code with AppleScript's
-- `current date` function which makes this code *a lot* shorter
-- - Improved setup
-- - Refactored code
-- - Better documentation
-- 1.7: This script starts now on Sundays so that I have a "Monday"
-- project the week before.
-- 1.8: - Made code easier to read (hopefully)
-- - I'm now setting defer and due times through AppleScript's
-- hour, minute, seconds
-- - Removed the ability to create 6 projects. This didn't make sense.
-- You can create 5 or 7 projects.
-- - Overall faster now.
-- set your preferred project properties here
-- the defer and due time is calculated as "seconds counting from hour 0"
-- uses 24 hour clock; 8am is 8 * 60 * 60 = 28800
-- you can use a different defer and due time for weekends,
-- if you tend to sleep longer on weekends like I do.
set deferTime to "8"
set dueTime to "17"
set deferTimeWeekend to "10"
set dueTimeWeekend to "24"
-- do you want to create 5 or 7 Day Projects?
set totalDays to 7
-- setup project names
set nameDay1 to do shell script "date -v +1d +'%a: %d. %m. %Y'"
set nameDay2 to do shell script "date -v +2d +'%a: %d. %m. %Y'"
set nameDay3 to do shell script "date -v +3d +'%a: %d. %m. %Y'"
set nameDay4 to do shell script "date -v +4d +'%a: %d. %m. %Y'"
set nameDay5 to do shell script "date -v +5d +'%a: %d. %m. %Y'"
set nameDay6 to do shell script "date -v +6d +'%a: %d. %m. %Y'"
set nameDay7 to do shell script "date -v +7d +'%a: %d. %m. %Y'"
-- setup defer dates
set startDay1 to (current date) + 1 * days
set startDay2 to (current date) + 2 * days
set startDay3 to (current date) + 3 * days
set startDay4 to (current date) + 4 * days
set startDay5 to (current date) + 5 * days
set startDay6 to (current date) + 6 * days
set startDay7 to (current date) + 7 * days
set {startDay1's hours, startDay1's minutes, startDay1's seconds} to {deferTime, 0, 0}
set {startDay2's hours, startDay2's minutes, startDay2's seconds} to {deferTime, 0, 0}
set {startDay3's hours, startDay3's minutes, startDay3's seconds} to {deferTime, 0, 0}
set {startDay4's hours, startDay4's minutes, startDay4's seconds} to {deferTime, 0, 0}
set {startDay5's hours, startDay5's minutes, startDay5's seconds} to {deferTime, 0, 0}
set {startDay6's hours, startDay6's minutes, startDay6's seconds} to {deferTimeWeekend, 0, 0}
set {startDay7's hours, startDay7's minutes, startDay7's seconds} to {deferTimeWeekend, 0, 0}
-- setup due dates
set dueDay1 to (current date) + 1 * days
set dueDay2 to (current date) + 2 * days
set dueDay3 to (current date) + 3 * days
set dueDay4 to (current date) + 4 * days
set dueDay5 to (current date) + 5 * days
set dueDay6 to (current date) + 6 * days
set dueDay7 to (current date) + 7 * days
set {dueDay1's hours, dueDay1's minutes, dueDay1's seconds} to {dueTime, 0, 0}
set {dueDay2's hours, dueDay2's minutes, dueDay2's seconds} to {dueTime, 0, 0}
set {dueDay3's hours, dueDay3's minutes, dueDay3's seconds} to {dueTime, 0, 0}
set {dueDay4's hours, dueDay4's minutes, dueDay4's seconds} to {dueTime, 0, 0}
set {dueDay5's hours, dueDay5's minutes, dueDay5's seconds} to {dueTime, 0, 0}
set {dueDay6's hours, dueDay6's minutes, dueDay6's seconds} to {dueTimeWeekend, 0, 0}
set {dueDay7's hours, dueDay7's minutes, dueDay7's seconds} to {dueTimeWeekend, 0, 0}
-- create new projects in OmniFocus
tell application "OmniFocus"
tell default document
set dayProjects to folder "Day Projects"
tell dayProjects
set projectDay1 to make new project with properties {name:nameDay1, defer date:startDay1, due date:dueDay1, singleton action holder:true}
set projectDay2 to make new project with properties {name:nameDay2, defer date:startDay2, due date:dueDay2, singleton action holder:true}
set projectDay3 to make new project with properties {name:nameDay3, defer date:startDay3, due date:dueDay3, singleton action holder:true}
set projectDay4 to make new project with properties {name:nameDay4, defer date:startDay4, due date:dueDay4, singleton action holder:true}
set projectDay5 to make new project with properties {name:nameDay5, defer date:startDay5, due date:dueDay5, singleton action holder:true}
if totalDays = 7 then
set projectDay6 to make new project with properties {name:nameDay6, defer date:startDay6, due date:dueDay6, singleton action holder:true}
set projectDay7 to make new project with properties {name:nameDay7, defer date:startDay7, due date:dueDay7, singleton action holder:true}
end if
end tell
end tell
end tell
Copy link

ghost commented Dec 30, 2015

I'd love to try nesting my Day Projects folder within another folder such as my Work folder. I see the line "set dayProjects to folder "Day Projects"" in the script above, but I'm not sure what the syntax is for nesting Day Projects within Work. Using "set dayProjects to folder "Work :: Day Projects"" doesn't appear to work.

@Zettt
Copy link
Author

Zettt commented Jan 7, 2016

set dayProjects to folder "Day Projects" of folder work? I don't know. I'd love if you try to figure this kind of stuff out by yourself.

Copy link

ghost commented Jan 7, 2016

This is beyond my pay grade, but I've figured out a solution.

Replace the line
set dayProjects to folder "Day Projects"
with the following:
set dayProjects to first flattened folder where its name = "Day Projects"

The kicker here is that this will find the first folder with the name specified. If I have a Day Projects sub-folder within both my Work folder and Life folder, this script would only fill in one of those folders: the first one in the list. I have no idea if "second flattened folder" or "third flattened folder" works as interpretable syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment