Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a script to start a Session session
- Loading branch information
1 parent
e1f3ec7
commit e3f7309
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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")) { | ||
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; | ||
})(); |