Skip to content

Instantly share code, notes, and snippets.

@Govan
Created July 23, 2015 18:47
Show Gist options
  • Save Govan/cf11f2e9f548afa28cd7 to your computer and use it in GitHub Desktop.
Save Govan/cf11f2e9f548afa28cd7 to your computer and use it in GitHub Desktop.
//============= Move Durations from titles back into Estimates
Omnifocus = Application("OmniFocus");
Omnifocus.includeStandardAdditions = true;
app = Application.currentApplication()
app.includeStandardAdditions = true
app.displayNotification("I'm about to parse durations from titles back into tasks", {withTitle: "OF2 Cleanup"})
document = Omnifocus.documents()[0];
allTasks = document.flattenedTasks();
Progress.totalUnitCount = allTasks.length;
for (t in allTasks){
Progress.completedUnitCount++;
tt = allTasks[t];
name = tt.name();
durationFromName = (name+"").match(/{([0-9]+m)}/);
if(durationFromName) {
durationFromName = durationFromName[1];
durationFromTask = tt.estimatedMinutes()+"m";
if(durationFromTask != durationFromName) {
console.log(durationFromName+" : "+tt.estimatedMinutes());
tt.estimatedMinutes = parseInt(durationFromName);
}
}
}
//==================================================
// Mark any item that doesn't have a duration
// with the clock emoji
Omnifocus = Application("OmniFocus");
Omnifocus.includeStandardAdditions = true;
app = Application.currentApplication()
app.includeStandardAdditions = true
app.displayNotification("I'm about to check for tasks that don't have a duration. This may take a while.", {withTitle: "OF2 Cleanup"})
document = Omnifocus.documents()[0];
allTasks = document.flattenedTasks();
Progress.totalUnitCount = allTasks.length;
tasksThatDidntHaveDuration = 0;
for (t in allTasks){
Progress.completedUnitCount = Progress.completedUnitCount+1;
task = allTasks[t];
// Ignore tasks that are Completed or Containers
if(task.completed() || (task.numberOfTasks() > 0)) {
continue;
}
// Ignore tasks in the inbox and those of non-active Projects
project = task.containingProject();
if(!project || (project.status() != "active")) { continue; }
// Ignore Tasks that are really empty Projects
if(!task.parentTask()) { continue; }
duration = task.estimatedMinutes();
if(!duration) {
tasksThatDidntHaveDuration++;
alreadyMarked = task.name().match(/⏰/);
if(!alreadyMarked) {
task.name = (task.name()+" ⏰");
}
}
}
app.displayNotification(tasksThatDidntHaveDuration+" tasks had no Estimated Time.\nSearch for ⏰ to see them.", {withTitle: "OF2 Cleanup"})
//==================================================
// Add durations to task names as a suffix
Omnifocus = Application("OmniFocus");
Omnifocus.includeStandardAdditions = true;
app = Application.currentApplication()
app.includeStandardAdditions = true
app.displayNotification("I'm about to add durations to task names. This may take a while", {withTitle: "OF2 Cleanup"})
document = Omnifocus.documents()[0]
allTasks = document.flattenedTasks()
Progress.totalUnitCount = allTasks.length
for (t in allTasks){
Progress.completedUnitCount = Progress.completedUnitCount+1
tt = allTasks[t]
name = tt.name();
nameWithoutDuration = name.split("{")[0].trim()
duration = tt.estimatedMinutes();
if(duration) {
nameWithoutDuration = nameWithoutDuration.replace(" ⏰", "")
nameWithDuration = nameWithoutDuration + " {"+duration+"m}"
console.log(nameWithDuration)
tt.name = nameWithDuration;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment