Hacking together a "Follow up" automation

I’m trying to make an automation which duplicate the current task(s), pre-pends "Follow up on: " to the duplicated task, removes all current tags and sets the main tag to follow up and then completes the original task.

However I have no knowledge of javascript😢,
but I do have two pieces which do what I want 😃,
but I don’t know how to combine them.😢

Any help would be appreciated.

/*{
	"author": "John",
	"targets": ["omnifocus"],
	"type": "action",
	"identifier": "com.John.omnifocus.combined",
	"version": "1.0",
	"description": "Remove all tags and tag with follow up.",
	"label": "combined",
	"mediumLabel": "combined",
	"paletteLabel": "combined",
}*/
(() => {
	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 = "Follow up on: " + 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;
})();
(() => Object.assign(
    new PlugIn.Action(selection => {

        // USER DATA -----------------------------------------
        const tagName = 'Follow up';

        // OMNI JS CODE ---------------------------------------
        const omniJSContext = () => {
            // main :: IO ()
            const main = () => {
                return selection.tasks.map(x => (
                    x.removeTags(x.tags),
                    addTag(
                        tagFoundOrCreated(tagName)
                    )(x)
                ))
            };

            // FUNCTIONS --
            // OmniFocus OmniJS --------------------------------------------
            // addTag :: Tag Object -> OFItem -> OFItem
            const addTag = oTag => item => {
                item.addTag(oTag)
                return item
            }

            // tagFoundOrCreated :: Tag Name -> Tag Object
            const tagFoundOrCreated = strTag =>
                tagNamed(strTag) || new Tag(strTag)

            // MAIN -----------------------------------------
            return main()
        };

        return omniJSContext()

    }), {
        validate: selection => selection.tasks.length > 0
    }
))();

There is a “waiting on” script already created by @rosemaryjayne on the omni automation website which pretty much does this.

https://omni-automation.com/omnifocus/plug-in-complete-await.html

You should only need to follow the instructions to add/replace Tag after line 19 and change the “Waiting on” to “Follow up”.

@TheOldDesigner,

Thank you for your reply, I used that script as basis for mine, but after inserting the tag it didn’t recognise it because it was not a top level tag, I also want to remove all other tags which the second script does.

I’'m just looking for somebody who can combine the two scrips.

I might be able to hack together two applescripts but I would like an automation that works on my mobile devices as well.

Thanks for your input.

@jhncbrwn May I suggest you try this plug-in. By default it behaves as you described. You’ll only need to edit the settings text file to use your preferred labels (for the tag name and the task name prefix), and to delete any automatic task naming rules you don’t want.

@MultiDim Thanks for your reply.

Meanwhile I found something that works for me.

For anybody interested save this as an automation.

/*{
	"author": "John",
	"targets": ["omnifocus"],
	"type": "action",
	"identifier": "com.John.omnifocus.Duplicate-and-tag-with-Follow-up",
	"version": "1.0",
	"description": "Duplicate and tag with Follow up",
	"label": "Duplicate and tag with Follow up",
	"mediumLabel": "Duplicate and tag with Follow up",
	"paletteLabel": "Duplicate and tag with Follow up",
}*/
(() => {
	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 = "" + task.name;
			
			//This removes all tags
			dupTasks[0].clearTags()

			//This add the tag follow up
			dupTasks[0].addTag(tagNamed('Follow up')); 
			
			duplicatedTasks.push(dupTasks[0].id.primaryKey);

			task.markComplete();
		});
		//idStr = duplicatedTasks.join(",")

		//This shows the task after creating it
		URL.fromString("omnifocus:///task/" + idStr).open()
    });

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