[MacRuby-devel] Using scripting bridge to create new objects within a Cocoa App.

Kam Dahlin haxie1 at me.com
Sun Oct 28 11:19:05 PDT 2012


ScriptingBridge offers a couple of ways of creating objects. One is to use the generated classes and then just alloc/-init or -initWithProperties to create an object of that class type. 
The other is to use -classForScriptingClass on SBApplication to get the scripting class you want to create and then alloc/init to create an instance. The name of the scripting class can be found in the applications AppleScript dictionary. 

Once you have created an instance, it must be added to the proper container before it can be used. 

I would recommend reading the ScriptingBridge guide here: 
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html

As well as this Ars article:
http://arstechnica.com/apple/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge/

I have wrestled a lot with SB. It gets you about 75% of what you need but that last 25% is a real PITA. 
Good luck and I hope this helps. 

K
Sent from my iPhone

On Oct 28, 2012, at 9:30 AM, Kevin Poorman <kjp at brightleafsoftware.com> wrote:

> Morning,
> 
> 
> I've been trying to use MacRuby to drive an integration between a popular webservice and the stock Reminders.app. I'm attempting this through the scripting bridge and am running into difficulty getting the scripting bridge Create new objects within reminders.app, or notes.app, or any other app i've tried. 
> 
> Examplar code:
> 
> n = SBApplication.applicationWithBundleIdentifier("com.apple.notes")
> new_note = NotesApplication::NotesNote.new
>    #NoMethodError: undefined method `==' for "#<SBProxyByClass:0x403a45ea0>":String
> 
> Ok, so perhaps I need to give it some options. lets try name:
> 
> new_note = NotesApplication::NotesNote.new name = "foo"
> ArgumentError: wrong number of arguments (1 for 0)
>    (irb):138:in `<main>'
> 
> harumph. 
> 
> Ok well lets fire up the dictionary - it says the method is "make"
> n.methods(true,true).grep /make/i
>    # []
> hmm. ok
> NotesApplication.methods(true,true).grep /make/i
>    # []
> 
> I can't find the make method on any object and new is throwing an odd error that I can't seem to inspect. 
> 
> Help?
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20121028/3ec33f40/attachment-0001.html>


More information about the MacRuby-devel mailing list