The Big Picture

Most scriptable applications are designed with a hierarchical organization of their elements. For example, the OmniGraffle application edits documents that contain canvases that contain graphics that may contain text or images.

The illustration below shows the hierarchical structure of the scriptable OmniGraffle objects (both on macOS and iOS):

The OmniGraffle Hierarchy

When referencing specific scriptable objects, some applications require the inclusion of the full object hierarchy path in the reference, like this example that references the third graphic contained in the top canvas of the frontmost document:




app.documents[0].canvases[0].graphics[2]

However, for connivence and the sake of security, the scripting implementation in OmniGraffle implements an “implied document” concept (Portfolio) that assumes you are scripting the frontmost document. There is no need to indicate the canvas’ place in the actual application hierarchy. So, to address the top canvas in the frontmost document, the script is:




app.documents[0].canvases[0] //incorrect canvases[0] //correct

The same applies for the document object. The frontmost document is implied and does not need to be specified:




app.documents[0].name //incorrect document.name //correct

The following section shows the correct syntax for addressing objects within the OmniGraffle application:

Application

The Application object is represented by the abbreviation: app




app.name --> OmniGraffle

Stencils

Stencils are elements of the application object and incorporate their host application object in their references:

App > Stencil




app.stencils.length app.stencils[0].name

Stencil Graphics

References to graphics within a stencil include both the stencil and application objects:

App > Stencil > Graphic




app.stencils[0].graphics.length app.stencils[0].graphics[0].name

Documents

As mentioned above, the current document is implied and its reference does not include the parent application object.

Document




document.name

Document Windows

In the OmniGraffle scripting implementation, windows belong to documents, and their references include their parent implied document object:

Document > Window




document.windows.length

Document Selection

A document’s selection object belongs to the window class, which in turn, belongs to the parent implied document:

Document > Window > Selection




document.windows[0].selection document.windows[0].selection.graphics.length

Document Selection View|Canvas

The selection object has properties for accessing references to its containing view or canvas:

Document > Window > Selection > View




document.windows[0].selection.view.select([canvases[0].graphics[0]]) document.windows[0].selection.canvas.name

Canvases

Canvases are elements of the invisible Portfolio object that represents the implied document. If that’s a bit confusing, just understand that references to canvases don’t require any parental document or application objects. Canvas references begin with: canvases

Canvas




canvases.length canvases[0].name

Layers

Layers are elements of canvases and so include a reference to their parent canvas:

Canvas > Layer




canvases[0].layers.length canvases[0].layers[0].name

Graphics

Graphics belong to both canvases and layers. However, when referencing a graphic, only the parental canvas object is required:

Canvas > Layer > Graphic




canvases[0].layers[0].graphics.length canvases[0].layers[0].graphics[0].name

Images

Images belong to both the invisible Portfolio object and the Graphic object that contains them. You can address images globally in a document, using the Portfolio object, by beginning your reference with: images

Image




images.length images[0].originalSize

Images can also be referenced via their parental graphic object:

Canvas > Graphic > Image




canvases[0].graphics[0].image.originalSize

Page Geometry Classes

Graphics in OmniGraffle documents are described and altered using Page Geometry measurement constructs that are fully documented on the following pages:

To change the origin (position) or size of a graphic, you extract the Rect object that is the value of the graphic’s geometry property, alter the extracted copy, and then assign the altered copy as the new value of the graphic’s geometry property. For example, here is a script that changes the origin (position) of a selected graphic:

omnigraffle:///omnijs-run?script=slds%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Esolids%0Aif%28slds%2Elength%20%3E%200%29%7B%0A%09geo%20%3D%20slds%5B0%5D%2Egeometry%0A%09geo%2Eorigin%20%3D%20new%20Point%280%2C0%29%0A%09slds%5B0%5D%2Egeometry%20%3D%20geo%0A%7D
Changing the Postion of a Graphic
 

slds = document.windows[0].selection.solids if(slds.length === 1){ geo = slds[0].geometry geo.origin = new Point(0,0) slds[0].geometry = geo }

Use the same technique for changing the size of a graphic:

omnigraffle:///omnijs-run?script=slds%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Esolids%0Aif%28slds%2Elength%20%3E%200%29%7B%0A%09geo%20%3D%20slds%5B0%5D%2Egeometry%0A%09geo%2Esize%20%3D%20new%20Size%28300%2C300%29%0A%09slds%5B0%5D%2Egeometry%20%3D%20geo%0A%7D
Changing the Size of a Graphic
 

slds = document.windows[0].selection.solids if(slds.length === 1){ geo = slds[0].geometry geo.size = new Size(300,300) slds[0].geometry = geo }