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.circle"}*/(() => {const action = new PlugIn.Action(async function(selection, sender){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 CLIPSvar exportWrappers = []selection.items.forEach((row,index) => {textColumns.forEach(col => {if(row.valueForColumn(col)){atts = row.valueForColumn(col).attachmentsif(atts){atts.forEach(att => {wrapper = att.fileWrapperif(wrapper.type === FileWrapper.Type.File &&wrapper.preferredFilename.endsWith('.m4a')){exportWrappers.push(wrapper)}})}}})})// EXPORT THE ATTACHED AUDIO CLIPSif(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 Saverfilesaver = 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, stylesreturn (selection.items.length > 0)};return action;})();