Skip to content

Instantly share code, notes, and snippets.

@vjandrea
Created April 22, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjandrea/37ef3e1413d7ac88293692d898439301 to your computer and use it in GitHub Desktop.
Save vjandrea/37ef3e1413d7ac88293692d898439301 to your computer and use it in GitHub Desktop.
Sort Illustrator artboards alphabetically - by OMOTI
/**
Kudos to OMOTI
https://community.adobe.com/t5/illustrator/script-to-sort-artboard-list-alphabetically/m-p/9558396?page=1#M77799
*/
function sortArtboard() {
var doc = app.activeDocument,
properties = [],
i,
max;
function copyProperties(source) {
var props = {},
key;
for (key in source) {
try {
props[key] = source[key];
} catch (e) {
}
}
return props;
}
function pasteProperties(source, destination) {
var key;
for (key in source) {
destination[key] = source[key];
}
}
function compareName(a, b) {
var comparison = 0;
if (a.name > b.name) {
comparison = 1;
} else if (a.name < b.name) {
comparison = -1;
}
return comparison;
}
for (i = 0, max = doc.artboards.length; i < max; i += 1) {
properties.push(copyProperties(doc.artboards[i]));
}
properties.sort(compareName);
for (i = 0, max = doc.artboards.length; i < max; i += 1) {
pasteProperties(properties[i], doc.artboards[i]);
}
}
sortArtboard();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment