OO-PG0006
Plug-In: Append File Links to Note
This plug-in will append links to the chosen files to the note of the selected row.
Return to: OmniOutliner Plug-In Collection
Append File Links to Note
/*{
"type": "action",
"targets": ["omnioutliner"],
"author": "Otto Automator",
"identifier": "com.omni-automation.oo.append-file-links",
"version": "1.0",
"description": "Will append links to the chosen files to the note of the selected row.",
"label": "Append File Links to Note",
"shortLabel": "Add File Links",
"paletteLabel": "Add File Links",
"image": "doc.fill"
}*/
(() => {
const action = new PlugIn.Action(async function(selection, sender){
try {
outline = selection.outline
node = selection.nodes.pop()
item = node.object
var note = item.valueForColumn(outline.noteColumn)
if (note === null) {
note = new Text("", outline.noteColumn.style);
}
picker = new FilePicker()
picker.multiple = true
urls = await picker.show()
var delimiterObj = new Text(" ā¢ ", note.style)
var newLineObj = new Text("\n", note.style)
if(note.string.length > 0){note.append(newLineObj)}
urls.forEach((url, index) => {
linkName = url.lastPathComponent
link = new Text(linkName, note.style)
style = link.styleForRange(link.range)
style.set(Style.Attribute.Link, url)
note.append(link)
if(index !== (urls.length - 1)){
note.append(delimiterObj)
}
})
item.setValueForColumn(note, outline.noteColumn);
}
catch(err){
console.error(err.name, err.message)
}
});
action.validate = function(selection, sender){
// selection options: columns, document, editor, items, nodes, outline, styles
if (!selection.editor) {return false}
return (selection.nodes.length === 1)
};
return action;
})();