[MacRuby-devel] Scripting Bridge
mattaimonetti at gmail.com
Sun Nov 6 18:04:22 PST 2011
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.
On Thu, Nov 3, 2011 at 5:08 PM, Matt Aimonetti <mattaimonetti at 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:
> 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:
> *(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
>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the MacRuby-devel