How to: automate create project from task, then add project link to task?

Hello,

Along the lines of what @Kourosh has proposed in his wonderful Omnifocus books, I’d like to use anchor tasks in a kind of Navigation/Kanban board folder. In this model my projects are actually represented by tasks, where those “anchor” tasks link to my project plans (i.e. the Omnifocus “project”).

However, whereas @Kourosh uses a script to create the anchor task from the pre-existing project. I’d like to create the OF project from the anchor task, then copy the link from the project and place in the note of the anchor task. The OF project and anchor task would have the same name (save for maybe adding an emoji to the anchor task to signify that a corresponding OF project is in the database) and I’d want the OF project to go into a “Project Support” folder.

Does anyone do something like this or have any ideas for doing this? I’m not an expert on javascript, unfortunately, but if there are other ideas I could play around with I’d be interested to hear your thoughts.

Thanks for any help you can give!

1 Like

Hello all,
To answer my own post, I found the following javascript from @rosemaryjayne which gets me halfway there. I only need to figure out how to:
(1) create the project in a specific folder and
(2) rather than delete original task, keep that task and replace the note with a url to the newly created project.

I think there is a template in the automation site for creating a project in a folder, so I hope I can figure that out. But any ideas how I would copy the new project url and paste back into the note of the original task?

Thanks!

/*{
	"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, tags
		var task = selection.tasks[0]
		
		// store the task properties and objects
		var taskTitle = task.name
		var childrenWillComplete = task.completedByChildren
		var taskIsSequential = task.sequential
		var taskShouldUseFloatZone = task.shouldUseFloatingTimeZone
		var taskDeferDate = task.deferDate
		var taskDueDate = task.dueDate
		var taskEstimatedMinutes = task.estimatedMinutes
		var taskFlagged = task.flagged
		var taskNote = task.note
		var taskRRule = task.repetitionRule
		var taskAttachments = task.attachments
		var taskLinkedFileURLs = task.linkedFileURLs
		var taskNotifications = task.notifications
		var taskChildren = task.children
		var taskTags = task.tags
		
		// create the project
		var project = new Project(taskTitle)
		
		// apply properties
		project.task.sequential = taskIsSequential
		if (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 = taskNote
		if (taskRRule){project.task.repetitionRule = taskRRule}
		
		// apply tags
		if (taskTags != []){project.task.addTags(taskTags)}
		
		// add objects
		if (taskNotifications){
			taskNotifications.forEach(notif => {
				var notifKind = notif.kind
				if (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-tasks
		if (taskChildren.length > 0){moveTasks(taskChildren, project)}
		
		// delete the task
		deleteObject(task)
		
		// show the project
		document.windows[0].perspective = Perspective.BuiltIn.Projects
		document.windows[0].selectObjects([project])
		
	});

	action.validate = function(selection, sender){
		// validation code
		// selection options: tasks, projects, folders, tags
		return (selection.tasks.length === 1)
	};
	
	return action;
})();

Hey @numnumnum (great username btw),

I love the idea! If you or someone else figures out how to make this work, I’d love to know about it.

(Meanwhile, if I may, I would like to quibble with the word choice. Rather than “anchor” (which I use in as a term for a pen/paper mindfulness technique), I like using the word “launch task”. I will show myself out now.)

  • Kourosh

Thanks 🙏 @Kourosh for taking the time to respond. Of course I meant “launch task”, which is cited right from your book. I couldn’t remember your phrase and, since I’m on my Windows PC at work, was too lazy to look it up.

Thanks for your work on productivity and mindfulness!

Now focusing on the query,

I think to get the respective OF project into my “Project Support” folder, I could replace

var project = new Project(taskTitle)
with
var project = (new Project(taskTitle), folderNamed('Project Support'))

I’ll have to test that, then I’ll have to figure out how to get the OF project link back to the initial task. One option is to delete that task and then run @Kourosh 's “Engage” applescript on the project to create a new instance of the launch task, but I’d rather try to do it all through OmniAutomation if possible.

So I would have to replace:
// delete the task deleteObject(task)

With some other code to get the link from the project to the initial “Launch” task.

Thanks all!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.