OO-PG0012

Plug-In: Import Image Files

This plug-in will import the chosen image files, adding a row for each image. Requires the outline to have an added text column titled: “Image”"

Return to: OmniOutliner Plug-In Collection

Video: Import Image Files
Import chosen image files, adding a row for each image. Requires the outline to have an added text column titled: “Image”"
Import Image Files
 

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.pics-to-rows", "version": "1.0", "description": "Import chosen image files, adding a row for each image. Requires the outline to have an added text column titled: “Image”", "label": "Add Rows with Pictures", "shortLabel": "Pics to Rows", "paletteLabel": "Pics to Rows", "image": "person.crop.rectangle.stack" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ try { // check for titled text column var colTitle = "Image" imageColumn = columns.find(col => { return (col.type === Column.Type.Text && col.title === colTitle) }) if(!imageColumn){ errMsg = `There is no text column titled “${colTitle}” in this outline.` throw { name: "Missing Column", message: errMsg } } else { picker = new FilePicker() picker.folders = false picker.multiple = true picker.types = [FileType.image] urlsArray = await picker.show() var bStyle = document.outline.baseStyle urlsArray.forEach(url => { urlStr = url.string // get file name var filename = urlStr.substring(urlStr.lastIndexOf('/')+1) // remove file extension and encoding var baseName = filename.substring(0,filename.lastIndexOf('.')) baseName = decodeURIComponent(baseName) // import images url.fetch(function(data){ wrapper = FileWrapper.withContents(filename,data) textObj = Text.makeFileAttachment(wrapper, bStyle) rootItem.addChild( null, function(item){ item.topic = baseName item.setValueForColumn(textObj,imageColumn) } ) }) }) } } catch(err){ new Alert(err.name, err.message).show() } }); action.validate = function(selection, sender){ return true }; return action; })();