Repetetive action - any way to automate? Acorn 8

Fairly often, I find myself wanting to take the current canvas in Acorn, flatten it and save it as a PNG file. This involves several manual mouse tasks, which become repetetive.

I was wondering if there was any way to create a script, action or other type of automation to initiate the following 2 tasks:

  1. Layer → Flatten Image
  2. File → Save As… (PNG)

I assume I might be able to do this with JXA but is that the correct/only route to take?
Thanks ahead of time for any advice…

This is pretty easy to do in JavaScript. I’ve got a sample here: https://github.com/ccgus/AcornSDK/blob/master/javascript_plugins/Export%20as%20PNG.js

You don’t need to flatten the image either for this to work.

/*
How to install this plugin:
1) Choose Acorn's Help ▸ Open Acorn's App Support Folder menu item.
2) Place this script in the Plug-Ins folder (and make sure it ends with .js)
3) Restart Acorn.  The plugin will now show up in the Filter menu.
*/

function main(image, doc, layer) {
    
    var savePanel = NSSavePanel.savePanel();
    
    savePanel.setExtensionHidden(false);
    savePanel.setAllowedFileTypes(["public.png"]);
    savePanel.setNameFieldStringValue(`${doc.lastComponentOfFileName()}.png`)
    
    if (savePanel.runModal()) {
        
        var cgimg = doc.newCGImage();
        
        var data = NSMutableData.data();
        var imageDestination = CGImageDestinationCreateWithData(data, "public.png", 1, null);
        
        CGImageDestinationAddImage(imageDestination, cgimg, null);
        CGImageDestinationFinalize(imageDestination);
        
        data.writeToURL_atomically_(savePanel.URL(), true);
        
        CGImageRelease(cgimg);
        
    }
}
1 Like

@ccgus Wow, this works beautifully! Thanks so much for sharing this!

1 Like