OmniGraffle: Document

A Document is the top-level object in OmniJS. For security reasons, scripts can only address the frontmost document, they cannot query for or address other documents that may be open. Unlike other classes of objects, such as graphics, that can be addressed by index, the “current document” is simply referenced as document instead of app.documents[0] in your scripts.

The following documentation describes how open, create, save, and close documents, as well as how to access a document’s properties.

Open Document

To open an OmniGraffle file, a file URL is passed to the openDocument application method. This handler attempts to open the specified document and to return a reference to it asynchronously. If the document is already open, the reference to the open document is passed along.

Note that due to platform sandboxing restrictions, opening the document may fail if the application doesn’t have currently permission to access the given file URL. The document, if any, that is associated with the calling script can be passed along to help grant permission to open the new document.

The passed in function will return two arguments: the first (result) will be either either the Document reference or an Error. On success, the second argument (wasOpen) is a Boolean value specifying whether the document was already open.

app.openDocument(document,fileURL,function(result,wasOpen){}

sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. “com.omnigroup.omnigraffle.graffle-package”. Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. Nulla vitae elit libero, a pharetra augue.

fileURL = URL.choose("com.omnigroup.omnigraffle.graffle") if (fileURL == null){ throw new Error('user cancelled') } else { app.openDocument(document,fileURL,function(result,wasOpen){ if(result instanceof Document){ // processing code goes here cnvs = result.windows[0].selection.canvas console.log(cnvs.graphics.length) } else { throw new Error(result) } }) }
omnigraffle:///omnijs-run?script=fileURL%20%3D%20URL%2Echoose%28%22com%2Eomnigroup%2Eomnigraffle%2Egraffle%22%29%0Aif%20%28fileURL%20%3D%3D%20null%29%7B%0A%09throw%20new%20Error%28%27user%20cancelled%27%29%0A%7D%20else%20%7B%0A%09app%2EopenDocument%28document%2CfileURL%2Cfunction%28result%2CwasOpen%29%7B%0A%09%09if%28result%20instanceof%20Document%29%7B%0A%09%09%09%2F%2F%20processing%20code%20goes%20here%0A%09%09%09cnvs%20%3D%20result%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09%09%09console%2Elog%28cnvs%2Egraphics%2Elength%29%0A%09%09%7D%20else%20%7B%0A%09%09%09throw%20new%20Error%28result%29%0A%09%09%7D%0A%09%7D%29%0A%7D

Nullam id dolor id nibh ultricies vehicula ut id elit. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Cras mattis consectetur purus sit amet fermentum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec ullamcorper nulla non metus auctor fringilla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

New Document

Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. “com.omnigroup.omnigraffle.graffle-package”. Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. Nulla vitae elit libero, a pharetra augue.

Document.makeNewAndShow(function(doc){ cnvs = doc.windows[0].selection.canvas cnvs.canvasSizingMode = CanvasSizingMode.Fixed cnvs.size = new Size(612,792) cnvs.name = "Letter to Sally" })
omnigraffle:///omnijs-run?script=Document%2EmakeNewAndShow%28function%28doc%29%7B%0A%09cnvs%20%3D%20doc%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09cnvs%2EcanvasSizingMode%20%3D%20CanvasSizingMode%2EFixed%0A%09cnvs%2Esize%20%3D%20new%20Size%28612%2C792%29%0A%09cnvs%2Ename%20%3D%20%22Letter%20to%20Sally%22%0A%7D%29

Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Maecenas sed diam eget risus varius blandit sit amet non magna. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Nullam quis risus eget urna mollis ornare vel eu leo. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Document Properties

Name

Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id elit non mi porta gravida at eget metus. Curabitur blandit tempus porttitor. Curabitur blandit tempus porttitor. Sed posuere consectetur est at lobortis. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Maecenas sed diam eget risus varius blandit sit amet non magna.

Document Undo

Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

if(document.canUndo){document.undo()}
omnigraffle:///omnijs-run?script=if%28document%2EcanUndo%29%7Bdocument%2Eundo%28%29%7D

Document Redo

Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

if(document.canRedo){document.redo()}
omnigraffle:///omnijs-run?script=if%28document%2EcanRedo%29%7Bdocument%2Eredo%28%29%7D

Document Close

Close this document. This is not currently allowed if the current scripting environment is owned by the Document (you can close other documents, but not your own). Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

document.close()
omnigraffle:///omnijs-run?script=document%2Eclose%28%29

Document Save

Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

document.save()
omnigraffle:///omnijs-run?script=document%2Esave%28%29
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER