Acorn Acorn 6

Scripting Acorn

See also: Example AppleScript and JavaScript Scripts

You can script in Acorn using a couple of different languages- AppleScript, or JSTalk (also known as "Cocoa Script" which is pretty much JavaScript with some extra goodies).  You can edit JSTalk scripts using TextEdit- but you might have an easier time using something like Apple's Xcode (which is free), BBEdit, SubEthaEdit, or even TextMate.  These text editors offer niceties such as syntax coloring and line numbers, making it easier to write and debug your scripts.

If you don't know JavaScript, there are lots and lots of tutorials out on the web you should check out.

Scripting Acorn with AppleScript can be done from the AppleScript Editor, located in your Applications folder.

Writing plugins for Acorn in JSTalk

Here is an example for a quickly resizing your image in Acorn

function main(image, doc, layer) {

    var size = doc.canvasSize()

    var newWidth = Math.floor(size.width / 2);



Paste that into a next text file in your favorite editor, and save it to file named "Resize to 50%.jstalk" in Acorn's Plug-Ins folder (which you can get to by choosing the Help ▸ Open Acorn's App Support Folder). Restart Acorn and choose the menu item Filter ▸ Resize to 50%.  Your image should then resize to 50% of its original size.

So what is going on here?

Well, first off- whenever you save a file in your Acorn Plug-Ins folder, and it has the file extension "jstalk" - it will show up in the Filter menu.  Then, when the plugin is called, Acorn looks specifically for the function named "main" in your image, and then passes it a copy of the current layer's image.  Nothing was done directly with the image.  Instead Acorn was asked for the current document, and then resized it like in the previous script.

Here is another example.  This can go in a new file named "Resize Layer to 50%.jstalk", in the same Plug-Ins folder as before (and yes, you'll need to quit and restart Acorn for the plugin to show up):

function main(image, doc, layer) {

    return image.imageByApplyingTransform(CGAffineTransformMakeScale(.5, .5));


In this example, something is actually done with our new image (which is a CIImage by the way).  A new image is made by applying a transform to the original image, which scales it by 50%.  Return to that image.  You'll notice that when calling this function your layer has been replaced with a new layer, which is 50% of the original size.  However, your overall image size has not changed because you didn't change the document's size.

Before this plugin:

Pasted Graphic 1.tiff

And after:

Pasted Graphic.tiff

Scripting Acorn with JSTalk and Automator

If you download the JSTalk package (available from ), it comes with an Automator plugin.  When you combine the two, you can then make an action which will take files that you pass to it, and then do various things like resizing them:

function run(input, parameters) {

var acorn = [JSTalk application:"Acorn"];


    var idx = 0;


    while (idx < input.length()) {

        var filePath = input[idx];

        var doc = [acorn open: filePath];

        [doc scaleImageToHeight:200];

        [[doc dataRepresentationOfType:"public.png"] writeToFile: filePath + ".png"];

        [doc close];




return input;


The possibilities are endless.

If you would like to see a specific example, or you have a task that you would like to see some example code for contact: and we'll see if we can come up with a solution for you!

Scripting Acorn with AppleScript and Automator

Here is an example Automator action that will take the images passed to it, and web export them to PNG files.

on run {input, parameters}

repeat with anImage in the input

tell application "Acorn"

set newFile to (POSIX path of anImage) & ".png"

open anImage as alias

tell document 1

web export in newFile as PNG


end tell

end tell

end repeat

return input

end run

Scripting Acorn from JSTalk Editor (Deprecated).

In the examples below, a file named "jimi.jpg" will be located in the Pictures folder.  Here is a script that can be run from JSTalk Editor for opening an image and resizing it to 200 pixels wide:

var acorn = JSTalk.application("Acorn");

var doc = acorn.open_("/Users/gus/Pictures/Jimi.jpg");


The first line grabs a reference to Acorn, the application.  It tells Acorn to open up a document, located at /Users/gus/Pictures/Jimi.jpg.  The "open" function opens the document, and then on the final line resizes the image to be 200 pixels wide.  Pretty simple!

Here is another example, which is a bit more complicated:

var acorn = JSTalk.application("Acorn");

var filePath = "/Users/gus/Pictures/Jimi.jpg";

var doc = acorn.open_("/Users/gus/Pictures/Jimi.jpg");

var size = doc.canvasSize()

var newWidth = size.width / 2;


doc.dataRepresentationOfType("public.png").writeToFile(filePath + ".png");


The first couple of lines look familiar, but then adds something a little different.  Instead of resizing the image to 200 pixels wide, it resizes to half the width.  On line 5, notice the size of the image.  Then on line 6, notice a variable named "newWidth" that is half the width of the current size.  The image is then scaled on line 8, a copy of the image is saved as a PNG image, then written to a file.  Finally the document is closed.

Important:  If the document is closed without saving it first, the changes are lost.  To save the document before closing it, add:


So what else can be done with the document?  The official list of things are located in the file "ACPlugin.h", located in the Acorn SDK ( but here are some of them:

doc.layers() - returns an array of the layers.

doc.currentLayer() - return the current layer.

doc.cropToRect(NSRect) - crop a rect to a particular dimension.

doc.scaleImageToHeight(newHeight); - similar to scaleImageToWidth.

doc.canvasSize() - get the current size.

doc.setCanvasSize(NSSize) - set a new size.

Acorn documents inherit from NSDocument, so you can call all the methods located in NSDocument as well.

Note For App Store Users: If you've purchased Acorn from the Mac App Store, certain AppleScripts, and JSTalk scripts may not work for you because of sandboxing restrictions required by Apple.  The direct version of Acorn does not have these issues.