After a small plug-in problem (and then realizing that it would only show up as available when there was a task with a due date selected) I got this working perfectly and I’m very grateful for it! This is a huge boon to my workflow. Thank you!
1 Like
Thank you very much for this. Brilliant. I wrote before but did not send for sure …
Thanks man!!!
i added line
task.notifications.forEach(x => task.removeNotification(x)),
This line deleted previous notification to avoid duplicates.
thanks to unlocked2412
This plagins add notification to all tasks with due dates.
/*{
"type": "action"
}*/
// Twitter: @unlocked2412
(() => Object.assign(
new PlugIn.Action(selection => {
// OMNI JS CODE ---------------------------------------
const omniJSContext = () => {
const main = () => {
const
ts = document.windows[0].selection.tasks,
min = 60,
hour = 60*min,
day = 24 * hour,
relativeOffsets = [-(15 * min),-(30 * min), -(1 * hour), 1 * hour, 3 * hour, 6 * hour];
return map(task => {
return (
task.notifications.forEach(x => task.removeNotification(x)),
relativeOffsets.map(x => task.addNotification(x)),
task
)
})(ts)
};
// FUNCTIONS --
// JS Prelude --------------------------------------------------
// Just :: a -> Maybe a
const Just = x => ({
type: 'Maybe',
Nothing: false,
Just: x
});
// Nothing :: Maybe a
const Nothing = () => ({
type: 'Maybe',
Nothing: true,
});
// Tuple (,) :: a -> b -> (a, b)
const Tuple = a =>
b => ({
type: 'Tuple',
'0': a,
'1': b,
length: 2
});
// apply ($) :: (a -> b) -> a -> b
const apply = f =>
// Application operator.
x => f(x);
// compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
const compose = (...fs) =>
// A function defined by the right-to-left
// composition of all the functions in fs.
fs.reduce(
(f, g) => x => f(g(x)),
x => x
);
// fst :: (a, b) -> a
const fst = tpl =>
// First member of a pair.
tpl[0];
// length :: [a] -> Int
const length = xs =>
// Returns Infinity over objects without finite
// length. This enables zip and zipWith to choose
// the shorter argument when one is non-finite,
// like cycle, repeat etc
'GeneratorFunction' !== xs.constructor.constructor.name ? (
xs.length
) : Infinity;
// list :: StringOrArrayLike b => b -> [a]
const list = xs =>
// xs itself, if it is an Array,
// or an Array derived from xs.
Array.isArray(xs) ? (
xs
) : Array.from(xs || []);
// map :: (a -> b) -> [a] -> [b]
const map = f =>
// The list obtained by applying f
// to each element of xs.
// (The image of xs under f).
xs => [...xs].map(f);
// min :: Ord a => a -> a -> a
const min = a => b => b < a ? b : a;
// snd :: (a, b) -> b
const snd = tpl =>
// Second member of a pair.
tpl[1];
// take :: Int -> [a] -> [a]
// take :: Int -> String -> String
const take = n =>
// The first n elements of a list,
// string of characters, or stream.
xs => 'GeneratorFunction' !== xs
.constructor.constructor.name ? (
xs.slice(0, n)
) : [].concat.apply([], Array.from({
length: n
}, () => {
const x = xs.next();
return x.done ? [] : [x.value];
}));
// uncons :: [a] -> Maybe (a, [a])
const uncons = xs => {
// Just a tuple of the head of xs and its tail,
// Or Nothing if xs is an empty list.
const lng = length(xs);
return (0 < lng) ? (
Infinity > lng ? (
Just(Tuple(xs[0])(xs.slice(1))) // Finite list
) : (() => {
const nxt = take(1)(xs);
return 0 < nxt.length ? (
Just(Tuple(nxt[0])(xs))
) : Nothing();
})() // Lazy generator
) : Nothing();
};
return main();
};
return omniJSContext()
}), {
validate: selection =>
selection.tasks.every(
x => null !== x.dueDate
)
}
))();
And whether there is a way to check whether such a notification date is set, and if so, do not create a notification.
Because now it creates duplicates every time I run the script.
I deleted all reminders before the script, but it’s not always good …
The API has this property of Task
class:
var notifications
→Array
ofTask.Notification
read-only
An array of the notifications that are active for this task.