Plug-In: Import TaskPaper Template (iCloud)
This plug-in will display a menu of TaskPaper templates stored within in the OmniFocus iCloud folder, and then import the chosen template.
INSTRUCTIONS: TaskPaper template files (ending in “.taskpaper”) must be stored in a folder titled “TaskPaper Templates” placed with the default OmniFocus iCloud folder. When selected, the plug-in will scan the folder and present a menu/list of the found template files. Select the TaskPaper template to be imported and select the desired import destination, either Inbox or Projects.
IMPORTANT REQUIREMENT: For use on a macOS system, edit the plug-in to replace the placeholder “USERNAME” (line 19) with the name of the Home directory on your system (current user name).

Import TaskPaper Template
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.import-icloud-taskpaper-template",
"version": "1.0",
"description": "This plug-in will present a menu of the TaskPaper files stored in iCloud > OmniFocus > TaskPaper Templates folder. The chosen template will be imported.",
"label": "Import TaskPaper Template",
"shortLabel": "TaskPaper"
}*/
(() => {
const action = new PlugIn.Action(function(selection, sender){
// action code
// IDENTIFY “TaskPaper Templates” WITHIN THE CURRENT OMNI APP ICLOUD FOLDER
if (Device.current.iOS){
let icloudURL = "file:///private/var/mobile/
Library/ Mobile%20Documents/" } else if (Device.current.mac){
let currentUserName = "USERNAME" // replace with name of Home directory
let icloudURL = `file:///Users/${currentUserName}/
Library/ Mobile%20Documents/` }
let appName = app.name
let lastSegment = `iCloud~com~omnigroup~${appName}/
Documents/ TaskPaper%20Templates/` let sourceFolderURL = URL.fromString(icloudURL + lastSegment)
// SEARCH THE DIRECTORY FOR MATCHING FILES
try {
let filetype = new TypeIdentifier("com.taskpaper.text")
let searchPromise = sourceFolderURL.find([filetype], false)
searchPromise.then(urls => {
if (urls.length === 0){throw new Error("No files found.")}
console.log("urls:", urls)
// DISPLAY MENU OF FILE NAMES
let menuItems = urls.map(function(url){
let urlString = url.string
let lastItem = urlString.substring(urlString.
lastIndexOf('/') + 1) lastItem = lastItem.replace(/\.[^/.]+$/, "") // file extension
return decodeURIComponent(lastItem)
})
let menuIndexes = menuItems.map(function(item,index){return index})
let templateMenu = new Form.Field.Option(
"template",
null,
menuIndexes,
menuItems,
0
)
let destinations = ["Inbox", "Projects"]
let destinationMenu = new Form.Field.Option(
"destination",
null,
[0,1],
destinations,
0
)
let inputForm = new Form()
inputForm.addField(templateMenu)
inputForm.addField(destinationMenu)
let formPrompt = "Template and destination:"
let buttonTitle = "Continue"
let formPromise = inputForm.show(formPrompt, buttonTitle)
inputForm.validate = function(formObject){
return true
}
formPromise.then(function(formObject){
let templateIndex = formObject.values['template']
let chosenURL = urls[templateIndex]
let destinationIndex = formObject.values['destination']
let destination = destinations[destinationIndex].
toLowerCase() // PROCESS CHOSEN FILE
chosenURL.fetch(function(data){
let TaskPaperText = data.toString()
TaskPaperText = encodeURIComponent(TaskPaperText)
let urlStr = `omnifocus:///paste?target=${destination}&content=${TaskPaperText}`
URL.fromString(urlStr).open()
})
})
formPromise.catch(function(err){
console.error("form cancelled", err.message)
})
})
}
catch(err){
new Alert(err.name, err.message).show()
console.error(err)
}
});
action.validate = function(selection, sender){
// validation code
// selection options: tasks, projects, folders, tags, databaseObjects, allObjects
return true
};
return action;
})();
Return to: OmniFocus Plug-In Collection