-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappendorprepend.omnifocusjs
31 lines (31 loc) · 1.21 KB
/
appendorprepend.omnifocusjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use strict";
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Kaitlin Salzke",
"identifier": "com.KaitlinSalzke.AppendOrPrepend",
"version": "1.2.0",
"description": "Append or prepend text to the name of the selected task(s)",
"label": "Append or Prepend",
"shortLabel": "Append or Prepend",
"image": "text.append"
}*/
(() => {
const action = new PlugIn.Action(async (selection) => {
const tasks = [...selection.tasks, ...selection.projects.map((p) => p.task)];
// build form
const inputForm = new Form();
inputForm.addField(new Form.Field.String('textInput', 'Text To Append/Prepend', null, null), null);
inputForm.addField(new Form.Field.Checkbox('prependSwitch', 'Prepend', null), null);
// show form
await inputForm.show('', 'Continue');
// get form values and adjust task name(s)
const textValue = inputForm.values.textInput;
const prepend = inputForm.values.prependSwitch;
tasks.forEach((task) => task.name = prepend ? task.name = textValue + task.name : task.name + textValue);
});
action.validate = (selection) => {
return selection.tasks.length + selection.projects.length > 0;
};
return action;
})();