OO-PG0009

Plug-In: Export Audio Clips

This plug-in will export all of the audio clips attached to the text columns of the selected rows.

Return to: OmniOutliner Plug-In Collection

Export Audio Clips
 

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.export-audio-from-selected-rows", "version": "1.6", "description": "This plug-in will export all of the audio clips attached to the text columns of the selected rows.", "label": "Export Audio Clips from Selected Rows", "shortLabel": "Export Audio", "paletteLabel": "Export Audio", "image": "waveform" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ // action code // selection options: columns, document, editor, items, nodes, outline, styles try { // GET ARRAY OF VISIBLE TEXT COLUMNS (OMIT “NOTE BUTTON” COLUMN) var editor = document.editors[0] var textColumns = [noteColumn] columns.forEach(col => { if (editor.visibilityOfColumn(col)){ if (col.type === Column.Type.Text){ if (!textColumns.includes(col)){ textColumns.push(col) } } } }) if(textColumns.length === 0){ throw { name: "Missing Resource", message: "This document has no text columns." } } // GET ARRAY OF FILEWRAPPERS FOR ATTACHED AUDIO CLIPS var exportWrappers = [] selection.items.forEach((row,index) => { textColumns.forEach(col => { if(row.valueForColumn(col)){ atts = row.valueForColumn(col).attachments if(atts){ atts.forEach(att => { wrapper = att.fileWrapper if( wrapper.type === FileWrapper.Type.File && wrapper.preferredFilename.endsWith('.m4a') ){ exportWrappers.push(wrapper) } }) } } }) }) // EXPORT THE ATTACHED AUDIO CLIPS if(exportWrappers.length > 0){ fmtr = Formatter.Date.withFormat('dd/MM/yy·h·mma') dateSlug = fmtr.stringFromDate(new Date()) // "04/11/22·9·46PM" // Create and Show File Saver filesaver = new FileSaver() folderType = new FileType("public.folder") filesaver.types = [folderType] fldrwrapper = FileWrapper.withChildren( `Audio-Clips-${dateSlug}`, exportWrappers ) urlObj = await filesaver.show(fldrwrapper) console.log(urlObj.string) urlObj.open() } else { throw { name: "Missing Resource", message: "The selected rows contain no audio clips." } } } catch(err){ if(!err.causedByUserCancelling){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ // validation code // selection options: columns, document, editor, items, nodes, outline, styles return (selection.items.length > 0) }; return action; })();