Plug-In: Duplicate Selected Projects to New Folder
Duplicates the selected projects to a new folder and sets the status of the duplicated projects to Active. Good for use with stored “On-Hold” projects!
Return to: OmniFocus Plug-In Collection
Duplicate Selected Projects to New Folder
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.duplicate-project-to-new-folder",
"version": "1.0",
"description": "Duplicates the selected projects to a new folder and sets the status of the duplicated projects to Active.",
"label": "Duplicate to New Folder",
"shortLabel": "Duplicate to New Folder",
"paletteLabel": "Duplicate to New Folder",
"image": "gearshape"
}*/
(() => {
var action = new PlugIn.Action(async function(selection, sender){
var items = selection.projects
var textInputField = new Form.Field.String(
"folderName",
"Folder Title",
null
)
var statusMenuField = new Form.Field.Option(
"statusIndex",
"Project Status",
[0,1],
["Active", "On-Hold"],
0
)
var inputForm = new Form()
inputForm.addField(textInputField)
inputForm.addField(statusMenuField)
inputForm.validate = function(formObject){
var textValue = formObject.values['folderName']
if(!textValue){return false}
return true
}
var formObject = await inputForm.show("Name for folder:","Continue")
var folderName = formObject.values["folderName"]
var folder = new Folder(folderName)
var statusIndex = formObject.values["statusIndex"]
var statusType = [Project.Status.Active, Project.Status.OnHold][statusIndex]
var duplicatedItems = duplicateSections(items, folder.beginning)
duplicatedItems.forEach(item => item.status = statusType)
var folderID = folder.id.primaryKey
URL.fromString("omnifocus:///folder/" + folderID).open()
});
action.validate = function(selection, sender){
return (selection.projects.length > 0)
};
return action;
})();