I want to write an AppleScript that creates projects in OmniFocus where their defer date and due date is set to any weeks' start and end day.
The result should look like this:
weeknumber: day1. month1. year1 - day2. month2. year2
Where weeknumber
is replaced with a weeks' week number. day1
, month1
and year1
take weeknumber
s' week number and parse it to that days' date. So for week number 09 in 2016 that would be 29. 02. 2016
. The first week ends (day2
and so forth) end on 06. 02. 2016
. So the result for the first week of 2016 would look like this:
09: 29. 02. 2016 - 06. 02. 2016
From the shell it is possible to get the last day of a month like so:
date -v 1d -v 3m -v 16y -v -1d +'%V: %d. %m. %Y'
09: 29. 02. 2016
In AppleScript you can turn any string, e.g. returned from a shell script (date
) into a date object with the syntax:
set lastDayShell to do shell script "date -v 1d -v 3m -v 16y -v -1d +'%V: %d. %m. %Y'"
set lastDay to date lastDayShell
The command to add a new project to OmniFocus is this:
tell application "OmniFocus"
tell default document
set weekNumbers to folder "Week Numbers"
tell weekNumbers
set project1 to make new project with properties {name:"09: 29. 02. 2016", defer date:firstDay, due date:lastDay, singleton action holder:true}
end tell
end tell
end tel
I know all of that. I just can't find a resource that says how to get the first and last day of any week. I want to set the defer date of any weeks' start to the first of the week, and the due date to the last day.