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 Dates 24-Hours
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.push-due-one-day",
"version": "1.0",
"description": "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.",
"label": "Push Due One Day",
"shortLabel": "Push Due 24",
"paletteLabel": "Push Due 24",
"image": "24.circle.fill"
}*/
(() => {
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 confirmationSound = "Purr"
var storedSoundIndx = 10
} else {
var confirmationSound = soundNames[storedSoundIndx]
}
if(app.shiftKeyDown){
checkSwitchField = new Form.Field.Checkbox(
"shouldPlaySound",
"Play sound after adjusting due 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]
}
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
}
}
}
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;
})();