Task Linked Files

A task Linked File is a file reference in URL format for a file that is linked to a task. Omni Automation in OmniFocus (v3.8+) provides the ability to add and remove file links to/from tasks.

File links are often used in place of task attachments in order to minimize the size of the data added to the OmniFocus database. The inclusion of large files in a synced OmniFocus database can compromise performance across devices.

Task Linked File Properties

There is one property regarding Linked Files for the Task class:

Task Linked Files Functions

The functions of the Task class dealing with the management of file links.

Adding File Links

Task File Links are instances of the URL class with each instance representing a file.

The following example plug-in demonstrates how create File Link instances from chosen files and add them to a selected task.

Add Chosen Files to Task as Links

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automaator", "identifier": "com.omni-automation.of.add-linked-files-to-task", "version": "1.0", "description": "This action will add chosen files as file links to the selected task.", "label": "Add File Links to Task", "shortLabel": "Add File Links" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var task = selection.tasks[0] var picker = new FilePicker() picker.folders = false picker.multiple = true // Generic types: FileType.image, FileType.pdf, FileType.plainText, etc. // https://omni-automation.com/shared/filetypes.html picker.types = null // any file type picker.show().then(urlsArray => { urlsArray.forEach(url =>{ task.addLinkedFileURL(url) }) }) }); action.validate = function(selection, sender){ // validation code return (selection.tasks.length === 1) }; return action; })();

Deleting File Links

Should you wish to remove file links from their assigned task, Omni Automation provides two mechanisms for deleting existing file links:

Deleting All File Links of Selected Tasks

var tasks = document.windows[0].selection.tasks tasks.forEach(task =>{ var urls = task.linkedFileURLs console.log(urls) urls.forEach(url => { task.removeLinkedFileWithURL(url) }) })