[MacRuby-devel] Scripting Bridge

Matt Aimonetti mattaimonetti at gmail.com
Thu Nov 3 17:08:59 PDT 2011

If you call "methods(true, true).grep /export/i" on one of your objects and
you get a method signature such as:

That means you need to call it as shown in my example:
page.exportFormat("tagged text/PDF", to:"/Users/mattetti/tmp/page2.pdf",
showingOptions: false, using: app.PDFExportPresets.first, versionComments:
"test", forceSave: true)

Which is like calling a method with a param and a hash of params with the
keys of the hash being the selector elements (it uses Ruby 1.9's hash
exportFormat(param, key: value, key: value, key: value)

If you look at the indesign header file the function signature looks like

- (void) *exportFormat*:(id)format *to:*(id)to *showingOptions:*(BOOL)
showingOptions *using:*(inDesignPDFExportPreset *)using_
*)versionComments *forceSave:*(BOOL)forceSave;  // Exports the object(s) to
a file.

In blue, you can see the expected type, in bold the method signature and in
gray the named given to the params (not important).

I figure the index numbers means the position of the param in the list.
> This has not worked perfectly and yours did not seem to match up perfectly
> or else I am missing something.  How do we figure out syntax for these
> other
> than trial and error?

I opened up a macirb session and used Ruby's introspection tools +
applescript editor which has some extra hints on the expected params.
For instance, I got a page object and I did:

>> methods = (page.method(true, true) - Object.new(true, true)).sort

That would give you an array of all the methods available on "page", for
the params, I referred to header file and the applescript editor dictionary
I can't find the small script I wrote, but writing a simple/dumb parser for
the obj-c header file that would give you a proper documentation for all
methods available should be very trivial. (I'm about to take off for a long
flight, I might work on that if my 16 months daughter decides to sleep for
most of the trip ;))

The bottom line is that using BridgeScript is harder that it should be
especially when the provided APIs aren't well designed. Ars Technical has a
good tutorial on how to script safari and evernote:

An app that would let you pick a 3rd party app and would run sdef/sdp, let
you browse the classes/functions, read the comments and generate a BS file
would be of a huge help.

Another thing that would be great is MacRuby support for OSA

I believe this is something Laurent still wants to have in for 1.0.

- Matt

On Thu, Nov 3, 2011 at 4:34 PM, Spencer Rose <dspencerr at gmail.com> wrote:

> And now I am reading chapter 8 of your book again because
> I remembered something about noMethodErrors and selectors.
> Starting to make sense.  Stay tuned.  :)
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20111103/adf106ef/attachment-0001.html>

More information about the MacRuby-devel mailing list