So here is some sample Ruby Appscript for OmniGraffle, for those who are interested. I did an application in AppleScript which take data from Numbers and builds a diagram in OmniGraffle. The problem was it was too slow to be useful. (I mean, I let it run over night and it was still chugging away in the morning.) So, I switched to Ruby and Appscript. I'm running into some new problems, that I can't seem to sort out. If anybody can help that would be great. I will post additional questions on this thread as well as success.
The one thing I'm trying to get right is how to set the size of the text and the alignment of the text. Below is my code...
The one thing I'm trying to get right is how to set the size of the text and the alignment of the text. Below is my code...
Code:
begin; require 'rubygems'; rescue LoadError; end require "appscript" include Appscript # assumes the document specified is open and the canvas is named as specified _DocumentName = "Sample Scripting Diagram.graffle" _CanvasName = "Ruby Test Canvas" =begin --This is the AppleScript of the two shapes... tell application "OmniGraffle Professional" tell canvas of front window make new shape at end of graphics with properties {name: "Circle", textSize: {0.800000, 0.700000}, text placement: top, fill: no fill, textPosition: {0.100000, 0.150000}, origin: {75.000000, 194.857147}, autosizing: vertically only, size: {250.000000, 34.285713}, text: {text: "This Shape #1", font: "Helvetica-Bold", text: "This Shape #1"}, draws shadow: false} make new shape at end of graphics with properties {text placement: top, fill: no fill, origin: {100.000000, 400.000000}, autosizing: vertically only, size: {200.000000, 24.000000}, text: {text: "This Shape #2", text: "This Shape #2"}, draws shadow: false} end tell end tell =end puts "Working with canvas: #{_CanvasName} of document #{_DocumentName}" #puts app('OmniGraffle Professional 5').documents.name.get # => prints out the names of all the documents (looks like it includes templates, too) workingCanvas = app('OmniGraffle Professional 5').documents[_DocumentName].canvases[_CanvasName] # gets the canvas we want to work with. #Create a new shape without specifying propterties shapeOne = workingCanvas.graphics.end.make(:new => :shape) # Now I go down the list of properties and try to set them shapeOne.origin.set([100 , 200]) shapeOne.size.set([200 , 75]) shapeOne.text_placement.set(:top) # I've had some incosistant results with using 'top' in single quotes. However, the :top seems to work always shapeOne.text.set("This Shape #1") shapeOne.text.font.set("Helvetica-Bold") shapeOne.fill.set(:no_fill) # I tried putting 'no fill' instead of :no_fill and it doesn't seem to work. The result is fill: 0 shapeOne.draws_stroke.set(true) shapeOne.autosizing.set(:vertically_only) shapeOne.name.set('Circle') shapeOne.draws_shadow.set(false) #thisNewShape.text.alignment.set(:center) # This doesn't work and I can't seem to figure out how to set the alignment of the text #thisNewShape.text.size.set([10]) # This doesn't work and I can't seem to figure out how to set the size of the text #thisNewShape.vertical_padding.set([0]) #thisNewShape.side_padding.set([0]) shapeTwo = workingCanvas.graphics.end.make(:new => :shape , :with_properties => { :origin => [100 , 400] , :size => [200 , 75], :text_placement => :top , :text => "This Shape #2" , :fill => :no_fill ,:draws_stroke => true , :autosizing => :vertically_only , :name => 'Rectangle', :draws_shadow => false})