The Associated Files Control

Although it is titled the “Associated Files” control, a more accurate name might be the “Associated File Data” control, as this component of the Omni Automation Script action interface is used to pass the contents (data) of files into the action’s script through the use of the argument.files parameter.

The value of the argument.files parameter is an array of Data objects for the corresponding linked files, so argument.files[0] would represent the first data object (file) added to the control’s array.

(OmniFocus) Attaching a Chosen Image to a Task or Project

The following example Shortcuts workflow (shortcut) demonstrates the use of both the Data Input Socket and the Associated Files control to pass image information and data into the script code, by adding a chosen image to the notes of the currently selected OmniFocus task or project: (DOWNLOAD)

 1  “Open App” action • Makes OmniFocus the active application.

 2  “Select Files” action • Presents a file chooser dialog for selecting a file.

 3  File Path variable • A Shortcuts variable containing the file path (string) of the chosen file is added as the content of the “Text” action.

 4  File Data variable • A Shortcuts variable containing the file (data) of the chosen file is added to the Associated Files control.

(⬇ see below ) A Shortcuts workflow (shortcut) passing information and data for a chosen image file into the script of the “Omni Automation Script” action.


 5  Data Input Socket • A Shortcuts variable containing the stored file path of the chosen file is placed in the Data Input Socket.

 6  The argument.input Parameter • The chosen file’s file path is retrieved and stored in a variable for use in the script.

 7  The argument.files Parameter • The chosen file’s data is retrieved and stored in a variable for use in the script.

TIP: In Shortcuts, set the shortcut to be pinned to the Shortcuts menu in the system-wide menu bar.

Attach Chosen File to Selected Task or Project

(async () => { let sel = selection if(sel.tasks.length + sel.projects.length === 1){ if (sel.tasks.length === 1){ var selectedItem = sel.tasks[0] } else { var selectedItem = sel.projects[0] } } else { throw { name: "Selection Issue", message: "Please select a single project or task." } } let aFilePath = argument.input let fileName = aFilePath.substring(aFilePath.lastIndexOf('/') + 1) let fileData = argument.files[0] let wrapper = FileWrapper.withContents(fileName, fileData) selectedItem.addAttachment(wrapper) })().catch(err => { let alertPromise = new Alert(err.name, err.message).show() alertPromise.then(buttonIndex => {throw new Error(-128)}) })

(⬇ see below ) The macOS file picker dialog summoned by the “Select Files” action. NOTE: at the bottom left of the dialog is an option in the Media section for accessing the contents of the default Photos collection on the computer.


(⬇ see below ) The chosen image attached to the selected project.

The attached chosen image file

Floor plan image courtesy of Wikipedia


The next section of this documentation demonstrates how to use the “Omni Automation Plug-In” action.