/
Focus.omnijs
56 lines (50 loc) · 1.91 KB
/
Focus.omnijs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Brian Hicks",
"identifier": "zone.bytes.focus",
"version": "1.0",
"description": "Start and log a pomodoro for the selected task",
"label": "Focus",
"shortLabel": "Focus",
"paletteLabel": "Focus",
"image": "clock"
}*/
(() => {
var action = new PlugIn.Action(async (selection, sender) => {
try {
let task = selection.tasks[0]
let possibleCategories = [
"Personal",
"Team",
"Wandering Toolmaker",
];
let defaultCategory = possibleCategories[0];
for (let tag of task.tags) {
if (tag.name == "Wandering Toolmaker") {
defaultCategory = tag.name;
break;
} else if (tag.name == "teams" || (tag.parent && tag.parent.name == "teams") || tag.name == "work" || (tag.parent && tag.parent.name == "work")) {
defaultCategory = "Team";
break;
} else if (tag.name == "personal" || (tag.parent && tag.parent.name == "personal")) {
defaultCategory = "Personal";
break;
}
}
let focusForm = new Form();
focusForm.addField(new Form.Field.String("project", "Project", task.containingProject ? task.containingProject.name : null));
focusForm.addField(new Form.Field.Option("category", "Category", possibleCategories, possibleCategories, defaultCategory));
focusForm.addField(new Form.Field.String("minutes", "Minutes", "25"));
await focusForm.show("Focus on…", "Start");
let sessionUrl = URL.fromString(`session:///start?intent=${encodeURIComponent(focusForm.values.project)}&categoryName=${encodeURIComponent(focusForm.values.category)}&duration=${encodeURIComponent(focusForm.values.minutes)}`)
sessionUrl.open();
} catch (err) {
console.error(err);
}
});
action.validate = function(selection, sender){
return (selection.tasks.length === 1)
};
return action;
})();