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 columnvar 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 = falsepicker.multiple = truepicker.types = [FileType.image]urlsArray = await picker.show()var bStyle = document.outline.baseStyleurlsArray.forEach(url => {urlStr = url.string// get file namevar filename = urlStr.substring(urlStr.lastIndexOf('/')+1)// remove file extension and encodingvar baseName = filename.substring(0,filename.lastIndexOf('.'))baseName = decodeURIComponent(baseName)// import imagesurl.fetch(function(data){wrapper = FileWrapper.withContents(filename,data)textObj = Text.makeFileAttachment(wrapper, bStyle)rootItem.addChild(null,function(item){item.topic = baseNameitem.setValueForColumn(textObj,imageColumn)})})})}}catch(err){new Alert(err.name, err.message).show()}});action.validate = function(selection, sender){return true};return action;})();