

The reports I write for work usually include photographs. In short, we’ll find the sinks of the graph (the sources of the reverse of the graph), and then explore all reachable nodes.Next post Previous post Annotating photos with OmniGraffle The details of the algorithm are beyond the scope of this article, and you can read more about them here. We’ll now implement Tarjan’s algorithm in a new source file, GraphTarjan.swift. We now have all the pieces we need to run and visualize the output of Tarjan’s algorithm right in our OmniGraffle document’s canvas. In Xcode, create a new Swift file, OmniGraffleScripting.swift, and paste in the following code: import Cocoa import ScriptingBridge protocol SBObjectProtocol : NSObjectProtocol

This isn’t as bad as it sounds, since we only need to define the interfaces we’ll actually need. Since we don’t have a tool for auto-generating a Swift interface to OmniGraffle’s Scripting Dictionary, we’ll have to write our own.

In doing so, any Objective-C messages we would send to these “proxy” objects would get translated to Apple Events behind the scenes with some Objective-C runtime magic. Now we would be able to traverse through any open documents, talk to OmniGraffle’s canvas, manipulate shapes, and so on. We would then cast our SBApplication object to an OmniGraffleApplication (defined in the exported OmniGraffle.h file). In an Objective-C application, we would then proceed in importing the Scripting Bridge framework and initializing an instance of SBApplication with OmniGraffle’s bundle identifier. Sdef /Applications/OmniGraffle.app | sdp -fh -basename OmniGraffle We can generate an Objective-C interface for OmniGraffle’s Scripting Dictionary with the following command: Objective-C developers typically get started using Scripting Bridge by auto-generating Objective-C interfaces that correspond to an application’s Scripting Dictionary. Since Swift interoperates with Objective-C, we’ll be able to use Scripting Bridge to control OmniGraffle from Swift. Scripting Bridge allows developers to control AppleScript-enabled applications from languages other than AppleScript, including Python and Objective-C.
#Omnigraffle arrow mac os x#
To talk to OmniGraffle from Swift, we’ll use the Scripting Bridge framework, which was first introduced in Mac OS X 10.5 “Leopard”. Now switch to Xcode, navigate to File > New > Project and create a new OS X Command Line Tool written in Swift. A copy of the OmniGraffle document can be downloaded here. Rename the first canvas, Canvas 1, to Simple Graph and save the document. Note that it’s important to drag connections from the source node to the destination node as this determines the sources and destinations of line objects in OmniGraffle’s scripting interface merely changing the tail/head arrow type will not cut it.

Next, add directed edges with the Line tool, as shown below. With the Shape tool, add four circles representing four different nodes and label them A-D. We’ll start with a clean slate and use the Auto-Resizing template (found under the Imperial Units category). Next, head over to the File menu and select New. Close any existing documents you may have open in OmniGraffle. We’ll start by creating a simple directed graph in OmniGraffle. We’ll then run the algorithm on a graph in the OmniGraffle canvas, coloring any strongly-connected components we find. In this article, we’ll implement Tarjan’s algorithm for finding the strongly-connected components of a directed graph (in Swift). One day I thought to myself, “wouldn’t it be cool if we could implement a graph algorithm in, say, Swift, and run it directly on the OmniGraffle canvas?” With OmniGraffle Pro’s extensive Scripting Dictionary and OS X’s Scripting Bridge framework, we can do just that. OmniGraffle by The Omni Group is a fantastic diagramming tool for OS X, and anyone studying graph theory is bound to find it useful for working through the details of graph algorithms.
