Scripting OmniGraffle with Swift

I found this online

http://www.mattrajca.com/2015/05/22/exploring-graph-theory-with-omnigraffle-and-swift.html

and got most of it up and running, including updating the Swift syntax and renaming the OG object to their OmniGraffle6X names.

What I haven’t been able to do is figure out how to set a fillColor on a shape, or get text from the Shapes label ,or set text on the shapes Label. Can you help me out here?

Also any reference to code or documentation for how to do scripting using Swift would be very helpful.

Here’s my code. It crashes at the bottom of main.swift (it’s a command line tool project)

Any help would be appreciated. I want to get really good at this and will publish results on swiftest.io and github to help other folks.

I’m posting this to a Swift slack channel as well.

Whoops just updated the code.

OmniGraffle 6’s scripting API was developed for AppleScript, so most examples are in that language.
Though you may have seen we recently announced OmniJS, which will (when we release it!) allow you to write scripts in JavaScript.

I don’t have any particular examples of scripting OmniGraffle from Swift.

All that’s cool, but you may have heard that Swift is a scripting language as well and is quite popular :-) Be happy to work with you guys on it if you wanna. I just updated the project and right now it’s not even getting the application object correctly. I’m going to try using the .h header this weekend, might work better. I’m not a JavaScript fan and don’t want to have to learn the language to access the scripting API.

Oh and I updated everything to OmniGraffle7 which I just bought. When I generated the API into the .h file it’s now without a 6 or 7 in the variable names.

I agree it would be cool to have more direct support for scripting OmniGraffle from Swift. However, JavaScript is the most straightforward way for us to support scripting in our iOS apps, so that’s where we’re going.

More here: https://www.omnigroup.com/blog/looking-back-looking-ahead-2017-edition

cool, I’ll just follow and play. Should be fun.

I have to reacquaint myself with this…

Depending on what exactly you’re trying to accomplish, you might also check out GraphViz and the DOT format, which OmniGraffle imports.

just curious, fellow forumers…is there ANYONE out there besides me who is a Swift developer?

1 Like

I am… answering after “only” 1 year.

1 Like

Question: Why does it HAVE to be Swift? Yes, I understand the fashionable ness. But is there an integration or function need?

Learning other languages - such a JavaScript - is what programmers quite like to do. :-) Including me, though I have to say I find AppleScript more difficult than the many others I’m familiar with.

Not impossible to set up Swift as at the top of the thread, but the execution will be much slower than with running JS in the internal JSContext.

(Not because Swift is slow, but because the Swift+sdef route goes through the Apple Events interface - which certainly is slow, and which may now be less actively supported (for OmniGraffle) than the new interface to an embedded JS Context, which can be used on iOS as well as macOS).

not a JavaScript fan and don’t want to have to learn the language

Pff … takes two seconds – the good part of it is a small language – much smaller than Swift – once you have learned it you may even be in a position to discover whether you like using it or not :-)

Right; API boundary crossing tends to be expensive - and this one in particular is “the scenic route”.

Integrated into the engine - as OmniJS is - is bound to be quicker.