Plug-In: Sort Canvases by Name
This plug-in will alphanumerically sort the canvases.
Return to: OmniGraffle Plug-In Collection
Sort Canvases by Name
/*{
"type": "action",
"targets": ["omnigraffle"],
"author": "Otto Automator",
"identifier": "com-omni-automation.og.Sort Canvases by Name",
"version": "1.0",
"description": "Will sort the canvases by name.",
"label": "Sort Canvases by Name",
"shortLabel": "Sort by Name",
"paletteLabel": "Sort by Name",
"image": "square.3.layers.3d"
}*/
(() => {
const action = new PlugIn.Action(async function(selection, sender){
try {
if (canvases.length == 1){return true}
// get canvas names
canvasNames = canvases.map(cnvs => cnvs.name)
// sort the list and reverse the order
sortedNames = canvasNames.sort().reverse()
// iterate the reversed list of names
sortedNames.forEach(cnvsName => {
// locate canvas with matching name
for(i = 0; i < canvases.length; i++){
if (canvases[i].name.localeCompare(cnvsName) == 0){
targetCanvas = canvases[i]
break
}
}
// if canvas is not top canvas, move to top
if (targetCanvas.id !== canvases[0].id){
targetCanvas.orderBefore(canvases[0])
}
})
}
catch(err){
new Alert(error.name, err.message).show()
console.error(err)
}
});
action.validate = function(selection, sender){
return true
};
return action;
})();