Skip to content

Instantly share code, notes, and snippets.

@cwensel
Created April 10, 2020 17:20
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 cwensel/988006a5e209c21e591e1d04b74ac5b8 to your computer and use it in GitHub Desktop.
Save cwensel/988006a5e209c21e591e1d04b74ac5b8 to your computer and use it in GitHub Desktop.
Export all Omnigraffle canvases as images
/*{
"type": "action",
"description": "Export images from current document.",
"label": "Export Canvases",
"paletteLabel": "Export Canvases"
}*/
var _ = function () {
var action = new PlugIn.Action(function (selection) {
// Add code to run when the action is invoked
console.log("Invoked with selection", selection);
let types = ['com.adobe.pdf', 'public.svg-image']
let promises = []
let current = document.windows[0].selection.view.canvas
canvases.forEach(canvas => {
let name = canvas.name;
console.log("name", name);
document.windows[0].selection.view.canvas = canvas
promises = promises.concat(types.map(type => document.makeFileWrapper(name, type)));
});
// put it back
document.windows[0].selection.view.canvas = current
console.log("promises", promises)
Promise.all(promises).then(function (fileWrappers) {
let map = new Map();
fileWrappers.forEach(function (fileWrapper) {
let split = fileWrapper.preferredFilename.split(".");
let type = split[split.length - 1];
if (!map.has(type)) {
console.log("creating type: ", type);
map.set(type, []);
}
map.get(type).push(fileWrapper);
})
console.log("map:", map);
let children = [];
map.forEach((key,value)=>{
console.log("each:", value,key)
children.push( FileWrapper.withChildren(value,key));
})
Promise.all(children).then(function (childWrappers) {
let parent = FileWrapper.withChildren("images", childWrappers);
new FileSaver().show(parent);
})
})
.catch(function (error) {
console.log("Error", error);
});
});
action.validate = function (selection) {
console.log("selection", selection);
if (!selection) {
return false;
}
console.log("selection.document", selection.document);
return selection.document != undefined;
};
return action;
}();
_;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment