During my last flight I wrote a 20 lines object-C header parser which dumps a json structure of the header (kinda weird to convert a XML to a header to a JSON, I might want to review my approach soon or later).

I'll probably try to write a quick demo app that will load the json structure and let you browse the API, nothing fancy but enough for someone to hack around and make the app awesome.

- Matt


On Thu, Nov 3, 2011 at 5:08 PM, Matt Aimonetti <mattaimonetti@gmail.com> wrote:
If you call "methods(true, true).grep /export/i" on one of your objects and you get a method signature such as:
exportFormat:to:showingOptions:using:versionComments:forceSave:

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 format).
exportFormat(param, key: value, key: value, key: value)

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

- (void) exportFormat:(id)format to:(id)to showingOptions:(BOOL)showingOptions using:(inDesignPDFExportPreset *)using_ versionComments:(NSString *)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 doc.
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: http://arstechnica.com/apple/guides/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge.ars

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.


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@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@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel