Changing Canvas by script

Is there a way to switch canvas by script - either AppleScript or JavaScript?

Yes! While I believe it is possible in AppleScript as well, for JavaScript we have a Canvas Tools plug-in that may suit your needs.

See for more information on using Canvases in JavaScript.

Thanks for the swift reply! However looking at the list of functions, I can’t see how I’d do this? I can see functions that change the order of canvases, and a function to get the current canvas - but how do I set the current canvas, that is get OG to switch to showing that canvas?


You want to refer to the canvas by array index as described in

For example, the first canvas is:

var cnvs =[0].selection.canvas

The second canvas down from the top is:

var cnvs =[1].selection.canvas

If you want to iterate over the canvases, you use logic like you would iterate over any array to get all of the canvases and act on them. The script Rename in Current Order in the Canvas Tools plug-in has a nice example.

Thanks for continuing to assist - I think that I’m not being very clear.

For example, the Actions property of an object include “Switch to the next canvas”. I’m not trying to change the properties of any of the canvases, or their order in the document; I just want OG to switch to showing a different canvas (especially in Presentation mode) just as it does when I use the up or down arrows, or one of those Actions.

Is that possible?

Many thanks,

You can add an action that calls a script if you like. There is a built in “Jump To Canvas” action in OmniGraffle, so you don’t need a script to jump between canvases unless you want something more specific than the 6 options we provide. Select the shape, in the Properties Inspector under Action, set “Jump to Canvas” from the Drop Down menu. Then you pick which canvas to jump to. To do the jumping, use the Action tool or go into presentation mode

If you select an object in OmniGraffle Pro, in the Properties inspector you can set an action to AppleScript or JavaScript, and then change to that canvas by clicking on that object with the action tool (Or in presentation mode). If you do need a custom scripting action, try setting the Current View to the canvas that you want in your script.

Aha! Thanks Lanette - that’s exactly what I wanted. Sorry to be so dense, I didn’t realise the distinction between the order of canvases in the document, and the order of canvases in the window.

(What I’m trying to do is have an object with an action that includes first jumping to another canvas, and then hiding and showing layers on that canvas - I can do either with the built-in actions, but to do both requires a script.)

Thanks for persisting when I didn’t get it!

Hi, just getting familiar with automation in omni and wondered if there’s any reason the above wouldn’t work anymore? The majority of the examples as well as sals tools/og tools - on don’t work and typically fall over when referencing the canvas. Returns an ‘undefined’ error. What am I doing wrong?

‘copy as’ code from a shape works, just not the above. All I’m trying to do is loop through the canvas to copy text.

See for the examples of the correct and incorrect way to reference a canvas. Keep in mind, this changes the canvas showing in the view (center), but it may work so fast that you can’t see it. Undefined isn’t actually neccisarily an error. Unless you define a value for your variable or function to return, undefined is the default. The script below will go through each canvas leaving you viewing the last canvas in the view of the frontmost window.

canvases.forEach(function(cs){[0].selection.view.canvas = cs;


It seems that referencing the canvas is the problem. I get the following error ‘ReferenceError: Can’t find variable: canvases undefined:1’ whenever I try to reference something, even when copying the code above.

Do you have a document open with multiple canvases when running this? Are you running it from the console inside OmniGraffle? Can you check which version of macOS (Apple menu->About This Mac) and OmniGraffle (OmniGraffle>About OmniGraffle) you are running so that I can make sure I am testing the same thing that you are? When I run the script above inside the OmniGraffle Automation Console, I see page 2 of the frontmost document and if I add a graphic, it is added to the last canvas in the document. I’ve tested this in multiple documents in OmniGraffle Pro 7.9.4 with both macOS 10.13.6 and 10.14 including the most recent beta. If these versions match what you are using, please contact support so that we can troubleshoot this with you. Please email us at

Looks like it hasn’t been updated since 7.7 and ‘check for updates’ was turned off. It works now! Thanks

Awesome! We keep adding more OmniJS support in most versions, so you may have been missing many updates. Glad you solved the mystery.

Hi All,

Not sure this is the correct place for this but here goes. Please advise if there is a more appropriate place.

I have been able to create reasonably complex diagrams with Omnigraffle. Love it. Have somewhat antiquated programming knowledge. Have been able to use the automation console to create a multi-canvas document. Wanted to create functions because much of the diagrams are just reiterating the same graphic several times on multiple canvases. Started to create canvas borders on each canvas for document title, info, etc. Each of the canvases are created but when I go to create the specific page format graphics, they all appear on the canvases[0] canvas.

The `canvas indexing thing isn’t working for me.
var cnvs =[0].selection.canvas
var cnvs =[1].selection.canvas

Looking for guidance on reference manuals to understand what’s a available so that I can start to build an understanding of how to create docs with Omni Automation. Forums are great but I’m having trouble finding insights specifically for what I’m trying to do.

Thoughts / input?

Thank you in advance for reading through this. Cool stuff!!! Thanks.

I’m afraid there’s not much too much reference available. It’s kinda lame there’s no visual representation of the document model to be found anywhere.

What you’re looking for is probably

var cnvs = document.portfolio.canvases[0]

Hey bboc,

Thank you very much. That did the trick… very much appreciated.

Take care,

Hi Greg,

There is a visual representation of the document model at and more details there that may help with scripting OmniGraffle.


1 Like

Thank you Lanette. The internal constructs are a bit elusive for me now having little experience. Drawing stuff and copy as javascript are helping to see some of the internal constructs and reading through the forums are helping but haven’t stumbled onto a place where all of the internal constructs are defined has happened for me yet. Is there a good place for me to start that you would recommend? Thank you.

I’d recommend starting with the OmniGraffle Tutorial and using the API references which is either in the Automation menu, or at I like the online version because it’s easy to check out while I’m using the console.

We have a growing community of JavaScript users automating in OmniGraffle now, so if you run into a problem, try posting in the forums to see if any of us can help.