Plug-In: Delete Canvases

This plug-in will delete all but the currently selected canvas.

Return to: OmniGraffle Plug-In Collection

Delete All But Selected Canvas
  

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "identifier": "com-omni-automation.og.Delete All But Selected Canvas", "version": "1.0", "description": "This plug-in will delete every canvas except the selected canvas.", "label": "Delete All But Selected Canvas", "shortLabel": "Delete All But Selected Canvas", "paletteLabel": "Delete All But Selected Canvas", "image": "square.3.layers.3d.slash" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ try { alertTitle = "CONFIRMATION REQUIRED" alertMsg = "Are you sure you want to remove all but the single selected canvas?" alert = new Alert(alertTitle, alertMsg) alert.addOption("Cancel") alert.addOption("Remove") alert.show(function(result) { if (result == 0) { console.log("user cancelled") } else { cnvs = document.windows[0].selection.canvas if(cnvs.id !== canvases[0].id){ cnvs.orderBefore(canvases[0]) } for(var i = canvases.length; i--;) { if(i != 0){canvases[i].remove()} } } }) } catch(err){ if(!err.causedByUserCancelling){ new Alert(error.name, err.message).show() console.error(err) } } }); action.validate = function(selection, sender){ return (canvases.length > 1) }; return action; })();