This and many other great examples of "how to do FOO in MacRuby" lead me to 
wonder whether the wiki (or any wiki) is really being used to its fullest?   
Some real gems (no pun intended) have gone by, and it would be awesome for 
newcomers to have a place to go where they can explore a variety of "How can I 
make MacRuby do ..." examples and maybe even find links to sample projects or 
code snippets (like this one) that various folks have kindly donated.  
Searching mailing list archives is a pain, in other words, and information like 
that below really ought to be preserved for posterity.

So....  If you're a reader of this list who would like to contribute to the 
overall health and success of the MacRuby community but don't feel comfortable 
or qualified to hack on the code base itself, this would be a GREAT 
contribution!

- Jordan

On Nov 15, 2011, at 3:11 PM, Kam Dahlin wrote:

> Hi Sophie,
> 
> Here is a little example, that I hope makes things more clear.
> 
> graffle = 
> SBApplication.applicationWithBundleIdentifier("com.omnigroup.OmniGrafflePro")
> 
> win = graffle.windows.first
> canvas = win.canvas
> 
> circle = 
> OmniGraffleProfessionalShape.alloc.initWithProperties({:name=>"Circle", 
> :origin=>[100.00, 100.00], :size=>[300, 300]})
> canvas.shapes.addObject(circle)
> 
> The example above uses the class name that should match what is in the header 
> file that you generated. 
> 
> You can also use a slightly different method for getting the correct class:
> 
> circle = 
> graffle.classForScriptingClass("shape").alloc.initWithProperties({:name=>"Circle",
>  :origin=>[100.00, 100.0], :size=>[300.0, 300.0]})
> 
> the -classForScriptingClass method takes the name of the class you would use 
> in Applescript and then returns the class that the ScriptingBridge machinery 
> expects. Just a slightly different approach and useful if you know the name 
> of the class you would use in Applescript, but not the actual name used by 
> ScriptingBridge.
> 
> If you look in the header that you generated for OmniGraffle, you will see a 
> bunch of @property declarations in each of the class definitions. The names 
> of these properties you use as the keys in the initWithProperties method. 
> Alternately you could also do:
> 
> circle = OmniGraffleProfessionalShape.alloc.init
> canvas.shapes.addObject(circle)
> circle.setName("Circle")
> circle.setOrigin([100.0, 100.0])
> circle.setSize([300.0, 300.0])
> 
> If you are going to set properties on an object, it must be added to a 
> container first. 
> 
> Most of this is explained pretty well in the ScriptingBridge documentation, 
> which is probably worth a look: 
> http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/AboutScriptingBridge/AboutScriptingBridge.html#//apple_ref/doc/uid/TP40006104-CH3-SW9
> 
> hth
> kam
> 
> P.S. the origin and size properties are actually defined as part of the 
> OmniGraffleProfessionalGraphic class which OmniGraffleProfessionalShape 
> inherits from.
> 
> On Nov 15, 2011, at 11:43 AM, Sophie wrote:
> 
>> Sorry for the sloppy subject line in my earlier question.
>> 
>> Thanks, Kam, Matt for your very helpful replies. 
>> 
>> Kam, any idea how I would initialize the alloc'd shape to be e.g. a Circle 
>> of some size at some position?
>> 
>> I generated the files with sdef & gen_bridge_metadata, found lots of useful 
>> things there. Is there something in these files that would lead me to:
>> 
>> shape = OmniGraffleShape.alloc.init 
>> canvas.shapes.addObject shape
>> 
>> ?  I don't see either alloc or init, or addObject in the 2 files.
>> 
>> Also, is there some reason why there is no corresponding "make ..." method 
>> in either file? Applescript gladly seems to call "make" (so does Ruby 
>> Appscript) on doc, canvas, or layer ... but I'm no Applescript guru :-(
>> 
>> Thanks !! 
>> 
>> 
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel@lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel@lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to