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… :slight_smile:

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… :slight_smile:

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

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 if anyone is able to help…

/*{
"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;
})();