Created
May 1, 2019 14:12
-
-
Save billygoat/ae462af4e08d901f1fa983a349b38506 to your computer and use it in GitHub Desktop.
Example Scriptable script for creating an OmniFocus project with tasks that have dates relative to an nth weekday of the month date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: brown; icon-glyph: apple-alt; | |
// share-sheet-inputs: file-url, url, plain-text; | |
let wom = 3 | |
let dow = 4 | |
var template = | |
`- Coordinate «month» CocoaHeads meeting @parallel(true) @autodone(false) | |
- Book a presenter @parallel(true) @autodone(false) @context(online) @tags(online) @due(«due» -2w 17:00) @defer(«due» -4w 00:00) | |
- Create the Meetup & Tweet/Slack about it @parallel(true) @autodone(false) @due(«due» -2w 17:00) @defer(«due» -2w 00:00) | |
shortcuts://x-callback-url/run-shortcut?name=Share%20CocoaHeads%20Meetup | |
- Tweet/Slack 1 week before @parallel(true) @autodone(false) @due(«due» -1w 17:00) @defer(«due» -1w 00:00) | |
shortcuts://x-callback-url/run-shortcut?name=Share%20CocoaHeads%20Meetup | |
- Tweet/Slack 2 days before @parallel(true) @autodone(false) @due(«due» -2d 17:00) @defer(«due» -2d 00:00) | |
shortcuts://x-callback-url/run-shortcut?name=Share%20CocoaHeads%20Meetup | |
- Tweet/Slack 1 day before @parallel(true) @autodone(false) @due(«due» -1d 17:00) @defer(«due» -1d 00:00) | |
shortcuts://x-callback-url/run-shortcut?name=Share%20CocoaHeads%20Meetup | |
- Request CocoaHeads reimbursement @parallel(true) @autodone(false) @due(«due» +1d 17:00) @defer(«due» +1d 00:00) | |
shortcuts://x-callback-url/run-shortcut?name=CocoaHeads%20Reimbursement | |
- Create next month’s project @parallel(true) @autodone(false) @due(«due» +1d 17:00) @defer(«due» +1d 00:00) | |
shortcuts://x-callback-url/run-shortcut?name=CocoaHeads%20OmniFocus%20Project | |
`; | |
let month = nextMonth(new Date()) | |
let monthName = month.toLocaleString('en-us', { month: 'long' }); | |
let due = nthWeekdayOfMonth(dow, wom, month) | |
let dueString = due.getFullYear() + "-" + ("0" + (due.getMonth() + 1)).slice(-2) + "-" + ("0" + due.getDate()).slice(-2) | |
template = template.replace(new RegExp("«month»", 'g'), monthName) | |
template = template.replace(new RegExp("«due»", 'g'), dueString) | |
Pasteboard.copy(template) | |
Script.complete() | |
// Calculate nth day of month | |
function nthWeekdayOfMonth(weekday, n, date) { | |
var date = new Date(date.getFullYear(), date.getMonth(), 1), | |
add = (weekday - date.getDay() + 7) % 7 + (n - 1) * 7; | |
date.setDate(1 + add); | |
return date; | |
} | |
// Get next month based on this month | |
function nextMonth(now) { | |
var current = now | |
if (now.getMonth() == 11) { | |
current = new Date(now.getFullYear() + 1, 0, 1); | |
} else { | |
current = new Date(now.getFullYear(), now.getMonth() + 1, 1); | |
} | |
return current | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment