Plug-In: Push Due Dates 24-Hours
Advances the due date of the selected projects or tasks twenty-four hours. Only items with due dates are processed.
TIP: Hold down Shift key when running plug-in to summon preferences dialog:
TIP: For quick access, assign keyboard shortcut or place plug-in in Toolbar
Return to: OmniFocus Plug-In Collection
Push Due and Defer Dates 24-Hours
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.push-due-defer-one-day",
"version": "1.0",
"description": "Advances the due and defer dates of the selected projects or tasks twenty-four hours. Items without due dates will use the default due time setting applied for tomorrow. Deferment time will be set to 12AM tomorrow for all selected items. TIP: Hold down Shift key when running plug-in to summon preferences dialog.",
"label": "Push Due & Defer One Day",
"shortLabel": "Push Due & Defer 24",
"paletteLabel": "Push Due & Defer 24",
"image": "24.circle"
}*/
(() => {
function playSystemAlert(alertFilename){
if(!alertFilename.endsWith(".aiff")){
alertFilename = alertFilename + ".aiff"
}
alertFilename = alertFilename.charAt(0).toUpperCase() + alertFilename.slice(1)
sysSoundsFldr = URL.fromString("/System/Library/Sounds/")
urlComps = URL.Components.fromURL(sysSoundsFldr, false)
urlComps.path = alertFilename
soundFileURL = urlComps.urlRelativeTo(sysSoundsFldr)
audioAlert = new Audio.Alert(soundFileURL)
Audio.playAlert(audioAlert)
}
var preferences = new Preferences() // NO ID = PLUG-IN ID
var soundNames = ["Basso",
"Blow", "Bottle", "Frog", "Funk", "Glass", "Hero", "Morse", "Ping", "Pop", "Purr", "Sosumi", "Submarine", "Tink"]
const action = new PlugIn.Action(async function(selection, sender){
try {
storedBoolean = preferences.readBoolean("shouldPlaySound")
if(storedBoolean === null){
preferences.write("shouldPlaySound", shouldPlaySound)
var shouldPlaySound = false
} else {
var shouldPlaySound = storedBoolean
}
storedSoundIndx = preferences.readNumber("confirmationSoundIndx")
if(storedSoundIndx === null){
preferences.write("confirmationSoundIndx", 10)
var storedSoundIndx = 10
var confirmationSound = "Purr"
} else {
var confirmationSound = soundNames[storedSoundIndx]
}
if(app.shiftKeyDown){
checkSwitchField = new Form.Field.Checkbox(
"shouldPlaySound",
"Play sound after adjusting due and defer dates",
shouldPlaySound
)
soundsOptionsMenu = new Form.Field.Option(
"confirmationSoundIndx",
"Confirmation Sound",
[0,1,2,3,4,5,6,7,8,9,10,11,12,13],
soundNames,
storedSoundIndx
)
inputForm = new Form()
inputForm.addField(soundsOptionsMenu)
inputForm.addField(checkSwitchField)
formPrompt = "Plug-in Options:"
buttonTitle = "Continue"
formObject = await inputForm.show(formPrompt, buttonTitle)
booleanValue = formObject.values['shouldPlaySound']
preferences.write("shouldPlaySound", booleanValue)
var shouldPlaySound = booleanValue
indx = formObject.values['confirmationSoundIndx']
preferences.write("confirmationSoundIndx", indx)
var confirmationSound = soundNames[indx]
}
// DEFERMENT DATE TIME = TOMORROW MORNING (12AM)
now = new Date()
today = Calendar.current.startOfDay(now)
duration = new DateComponents()
duration.day = 1
defermentDateTime = Calendar.current.dateByAddingDateComponents(today, duration)
// DERIVE A DEFAULT DUE DATE/TIME FOR TOMORROW
defaultDueTime = settings.objectForKey('DefaultDueTime')
//--> "17:00:00" (5PM)
console.log("DefaultDueTime", defaultDueTime)
timeElements = defaultDueTime.split(":")
dc = new DateComponents()
dc.day = dc.day + 1
dc.hour = Number(timeElements[0])
dc.minutes = Number(timeElements[1])
dc.seconds = Number(timeElements[2])
defaultDueDate = Calendar.current.dateByAddingDateComponents(today, dc)
// PROCESS THE SELECTED ITEMS
selectedItems = selection.databaseObjects
for (indx in selectedItems){
item = selectedItems[indx]
if (item instanceof Project || item instanceof Task){
if(item.dueDate){
dc = Calendar.current.dateComponentsFromDate(item.dueDate)
dc.hour = dc.hour + 24
newDueDate = Calendar.current.dateFromDateComponents(dc)
item.dueDate = newDueDate
} else {
item.dueDate = defaultDueDate
}
// SET DEFERMENT
item.deferDate = defermentDateTime
}
}
if(shouldPlaySound && Device.current.mac){playSystemAlert(confirmationSound)}
}
catch(err){
if(!err.causedByUserCancelling){
console.error(err.name, err.message)
new Alert(err.name, err.message).show()
}
}
});
action.validate = function(selection, sender){
// selection options: tasks, projects, folders, tags, databaseObjects, allObjects
return (selection.tasks.length > 0 || selection.projects.length > 0)
};
return action;
})();