Task to Project
Based upon a concept by noted automation expert Rosemary Orchard, this action incorporates the use of many task properties and related functions to turn the selected task into a new project, while retaining all properties, attachments, file links, notifications, sub-tasks, and notes of the source task.
Upon completion of the project, the selected task is deleted.
Task to Project
/*{"type": "action","targets": ["omnifocus"],"author": "Rosemary Orchard","identifier": "com.omni-automation.of.task-to-project","version": "1.0","description": "This action will create a new project duplicating the attributes and attachments of the selected task. The script will delete the selected task after the project has been created.","label": "Task to Project","shortLabel": "Task to Project"}*/(() => {const action = new PlugIn.Action(function(selection, sender){// action code// selection options: tasks, projects, folders, tagsvar task = selection.tasks[0]// store the task properties and objectsvar taskTitle = task.namevar childrenWillComplete = task.completedByChildrenvar taskIsSequential = task.sequentialvar taskShouldUseFloatZone = task.shouldUseFloatingTimeZonevar taskDeferDate = task.deferDatevar taskDueDate = task.dueDatevar taskEstimatedMinutes = task.estimatedMinutesvar taskFlagged = task.flaggedvar taskNote = task.notevar taskRRule = task.repetitionRulevar taskAttachments = task.attachmentsvar taskLinkedFileURLs = task.linkedFileURLsvar taskNotifications = task.notificationsvar taskChildren = task.childrenvar taskTags = task.tags// create the projectvar project = new Project(taskTitle)// apply propertiesproject.task.sequential = taskIsSequentialif (taskDueDate){project.task.dueDate = taskDueDate}if (taskDeferDate){project.task.deferDate = taskDeferDate}if (taskDueDate || taskDeferDate){project.task.shouldUseFloatingTimeZone = taskShouldUseFloatZone}if (taskChildren != []){project.task.completedByChildren = childrenWillComplete}project.task.note = taskNoteif (taskRRule){project.task.repetitionRule = taskRRule}// apply tagsif (taskTags != []){project.task.addTags(taskTags)}// add objectsif (taskNotifications){taskNotifications.forEach(notif => {var notifKind = notif.kindif (notifKind === Task.Notification.Kind.Absolute){project.task.addNotification(notif.absoluteFireDate)}if (notifKind === Task.Notification.Kind.DueRelative){project.task.addNotification(notif.relativeFireOffset)}})}if (taskAttachments){taskAttachments.forEach(attachment => {project.task.addAttachment(attachment)})}if (taskLinkedFileURLs){taskLinkedFileURLs.forEach(fileURL => {project.task.addLinkedFileURL(fileURL)})}// move sub-tasksif (taskChildren.length > 0){moveTasks(taskChildren, project)}// delete the taskdeleteObject(task)// show the projectdocument.windows[0].perspective = Perspective.BuiltIn.Projectsdocument.windows[0].selectObjects([project])});action.validate = function(selection, sender){// validation code// selection options: tasks, projects, folders, tagsreturn (selection.tasks.length === 1)};return action;})();