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)
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 () => {
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."
}
}
aFilePath = argument.input
fileName = aFilePath.substring(aFilePath.lastIndexOf('/') + 1)
fileData = argument.files[0]
wrapper = FileWrapper.withContents(fileName, fileData)
selectedItem.addAttachment(wrapper)
})().catch(err => {
alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(buttonIndex => {throw new Error(-128)})
})
Floor plan image courtesy of Wikipedia
Next…
The next section of this documentation demonstrates how to use the “Omni Automation Plug-In” action.