OmniFocus “Completed Task” Clean Up

I am looking for something that will trigger whenever a task is completed. Check for criteria outlined below and act accordingly. Just not sure where to start within OmniFocus. Any help would be greatly appreciated…

In the notes section of many of my tasks (not all) there are two hyperlinks; “Mail” & “PDF”

Since the majority of these types of tasks originate due to an email that I have either received or sent I place the actual text from the body of the email that I want to follow up on within the note section of the task. Following that text are the two links, outlined above, that are placed at the end of the note section within the task.

I use email text for quick reference while in OmniFocus. If I am ready to follow up I will then use the “Mail" link below the text to pull up that specific email and send a response. The “Mail” link is a deep link to an email within the default MacOS mail application which allows it me to pull it up on MacOS or iOS which is nice since I travel quite a bit.

Mail Link
message://%3C28AC20AB-631D-4315-80B5-E1E1CD4B939E%40smithgrp.net%3E

The same is true for the PDF link. It is just a PDF version of the same email. I realize it is redundant but that’s just me… :)

PDF Link
https://www.icloud.com/iclouddrive/05I58TiO_wcOiFijeLgTh6g#Cycle_Threshold_Values_-2021-01-24@_10.17.39_AM

I have been using this system for quite sometime and it works great for me. However I would like to add a step to OmniFocus that will clean up these links when I complete one of these tasks so that I do not have to do it manually. I realize that it does not actually NEED to be done but for me it does so I can sleep at night, again that’s just me… :)

When I complete a task and if that task contains a “Mail” or a “PDF” link I would like an AppleScript, Keyboard Maestro Macro, or a OmniFocus plugin that would pull up those links and do two things, one for each link;

Mail
Move the associated email to the trash, delete it (it currently resides in a “OmniFocus” folder within the mail app)

PDF
Move the PDF version of the email to another archive folder on my computer.

Thank you,
Mike

Well, you’re not asking for much are you? ;-)

Off the top of my head, and with the disclaimer that I’m still on v2 since v3 broke too much of my automation, here’s what I’m thinking:

  1. I don’t think anything can be done to automatically trigger immediately upon completion, but you can set up a script to run periodically using launchd that could look for items completed since it lasted ran and act only on those (if you don’t archive (manually or natively) completed tasks this could bog down your system)
  2. Mail might be tricky (I don’t even use a link to the message anymore, I just embed an attachment because the interaction was too fragile) but you should be able to use the message id in the link to tell Mail to move the message from OF folder to trash.
  3. This is probably the easiest because the file path is already there so just move the file to the desired location

Something that just occurred to me, I’ve never tried reading the embedded URL of a “pretty” link in OF notes. If you can’t access that, then everything above stalls at the starting line and you’d have to reconfigure your creation of these tasks to include the full URL in the text.

Lastly, certainly no judgement here on what you need for your system to work. See aforementioned, “I’m still on OF v2.” :-)

Thank you. I would think this could be done using a OF plugin but I know nothing about JS. I found this from Rosemary that looks at all selected tasks and manipulates them but I would need some help pulling the notes field from each selected task, I think I could get the rest of it figured out from there…

/*{
"author": "Rosemary Orchard",
"targets": ["omnifocus"],
"type": "action",
"identifier": "com.rosemaryorchard.omnifocus.complete-and-await-reply",
"version": "1.0",
"description": "Mark the currently selected task as complete and add a new task to await the reply.",
"label": "Complete and Await Reply",
"mediumLabel": "Complete and Await Reply",
"paletteLabel": "Complete and Await Reply",
}*/
(() => {
let action = new PlugIn.Action(function(selection) {
	let duplicatedTasks = new Array()
	selection.tasks.forEach(function(task){
		insertionLocation = task.containingProject
		if(insertionLocation === null){insertionLocation = inbox.ending}
		dupTasks = duplicateTasks([task], insertionLocation)
		dupTasks[0].name = "Waiting on reply: " + task.name;
		duplicatedTasks.push(dupTasks[0].id.primaryKey);
		task.markComplete();
	});
	idStr = duplicatedTasks.join(",")
	URL.fromString("omnifocus:///task/" + idStr).open()
});


action.validate = function(selection){
	return (selection.tasks.length >= 1)
};
    
return action;
})();

Thanks for not judging :)

Ah, I forgot about that type of functionality, using a script/plugin to do the “mark complete”. That would be the easiest way to activate the subsequent actions, as long as you remember not to check off the items manually.

Unfortunately, JS is not one of the languages I speak so I may have to tap out. If you can find some plugins working with notes, you may be able to reverse engineer what you need.

Getting the note should be as simple as task.note.

I think that @aeryn’s may be correct about the link formatting causing issues, but I haven’t played with it either.

Presumably from the script you would need to invoke a Keyboard Maestro macro or similar to deal with the Mail/iCloud part of the workflow?