Re: [MacRuby-devel] Scripting Bridge
I talked with Laurent and it said that the fact that the object type is SBObject is probably done on purpose by the inDesign API. - Matt On Tue, Nov 1, 2011 at 12:12 PM, Matt Aimonetti <mattaimonetti@gmail.com>wrote:
I generated the header file and looked at the description and I think that the issue us that the returned value isn't cast:
@property (copy) id appliedFont; // The font applied to the find glyph preference, specified as either a font object or the name of font family. Can return: font, string or nothing.
"id" in Objective-C means refers to an object that isn't typed (could be anything). That might be the reason why you get an object that isn't cast. There is a workaround and it's to use the properties hash:
framework 'Foundation' framework 'ScriptingBridge'
app = SBApplication.applicationWithBundleIdentifier('com.adobe.indesign') load_bridge_support_file 'inDesign.bridgesupport' doc = app.activeDocument doc.allParagraphStyles.each do |style| puts style.name puts style.properties["appliedFont"].name puts "~~~~~~~~~~~~~~" end
In my case it returns the following:
[No Paragraph Style] Minion Pro Regular ~~~~~~~~~~~~~~ [Basic Paragraph] Minion Pro Regular ~~~~~~~~~~~~~~
The available properties are: OTFContextualAlternate OTFDiscretionaryLigature OTFFigureStyle OTFFraction OTFHVKana OTFHistorical OTFJustificationAlternate OTFLocale OTFMark OTFOrdinal OTFOverlapSwash OTFProportionalMetrics OTFRomanItalics OTFSlashedZero OTFStretchedAlternate OTFStylisticAlternate OTFStylisticSets OTFSwash OTFTitling alignToBaseline allowArbitraryHyphenation appliedFont appliedLanguage appliedNumberingList autoLeading autoTcy autoTcyIncludeRoman balanceRaggedLines basedOn baselineShift bulletChar bulletsAlignment bulletsAndNumberingListType bulletsCharacterStyle bulletsTextAfter bunriKinshi capitalization characterAlignment characterDirection characterRotation cjkGridTracking composer desiredGlyphScaling desiredLetterSpacing desiredWordSpacing diacriticPosition digitsType dropCapCharacters dropCapLines dropCapStyle dropcapDetail endJoin fillColor fillTint firstLineIndent fontStyle glyphForm gradientFillAngle gradientFillLength gradientFillStart gradientStrokeAngle gradientStrokeLength gradientStrokeStart gridAlignFirstLineOnly gridAlignment gridGyoudori horizontalScale hyphenWeight hyphenateAcrossColumns hyphenateAfterFirst hyphenateBeforeLast hyphenateCapitalizedWords hyphenateLadderLimit hyphenateLastWord hyphenateWordsLongerThan hyphenation hyphenationZone id ignoreEdgeAlignment imported index jidori justification kashidas keepAllLinesTogether keepFirstLines keepLastLines keepLinesTogether keepRuleAboveInFrame keepWithNext keepWithPrevious kentenAlignment kentenCharacterSet kentenCustomCharacter kentenFillColor kentenFont kentenFontSize kentenFontStyle kentenKind kentenOverprintFill kentenOverprintStroke kentenPlacement kentenPosition kentenStrokeColor kentenStrokeTint kentenTint kentenWeight kentenXScale kentenYScale kerningMethod keyboardDirection kinsokuHangType kinsokuSet kinsokuType label lastLineIndent leading leadingAki leadingModel leftIndent ligatures maximumGlyphScaling maximumLetterSpacing maximumWordSpacing minimumGlyphScaling minimumLetterSpacing minimumWordSpacing miterLimit mojikumi name nextStyle noBreak numberingAlignment numberingApplyRestartPolicy numberingCharacterStyle numberingContinue numberingExpression numberingFormat numberingLevel numberingRestartPolicies numberingStartAt objectReference overprintFill overprintStroke paragraphDirection paragraphGyoudori paragraphJustification parent pointSize position positionalForm previewColor rensuuji rightIndent rotateSingleByteCharacters rubyAlignment rubyAutoAlign rubyAutoScaling rubyAutoTcyAutoScale rubyAutoTcyDigits rubyAutoTcyIncludeRoman rubyFill rubyFont rubyFontSize rubyFontStyle rubyOpenTypePro rubyOverhang rubyOverprintFill rubyOverprintStroke rubyParentOverhangAmount rubyParentScalingPercent rubyParentSpacing rubyPosition rubyStroke rubyStrokeTint rubyTint rubyType rubyWeight rubyXOffset rubyXScale rubyYOffset rubyYScale ruleAbove ruleAboveColor ruleAboveGapColor ruleAboveGapOverprint ruleAboveGapTint ruleAboveLeftIndent ruleAboveLineWeight ruleAboveOffset ruleAboveOverprint ruleAboveRightIndent ruleAboveTint ruleAboveType ruleAboveWidth ruleBelow ruleBelowColor ruleBelowGapColor ruleBelowGapOverprint ruleBelowGapTint ruleBelowLeftIndent ruleBelowLineWeight ruleBelowOffset ruleBelowOverprint ruleBelowRightIndent ruleBelowTint ruleBelowType ruleBelowWidth scaleAffectsLineHeight shataiAdjustRotation shataiAdjustTsume shataiDegreeAngle shataiMagnification singleWordJustification skew spaceAfter spaceBefore spanColumnMinSpaceAfter spanColumnMinSpaceBefore spanColumnType spanSplitColumnCount splitColumnInsideGutter splitColumnOutsideGutter startParagraph strikeThroughColor strikeThroughGapColor strikeThroughGapOverprint strikeThroughGapTint strikeThroughOffset strikeThroughOverprint strikeThroughTint strikeThroughType strikeThroughWeight strikeThru strokeAlignment strokeColor strokeTint strokeWeight tabList tatechuyoko tatechuyokoXOffset tatechuyokoYOffset tracking trailingAki treatIdeographicSpaceAsSpace tsume underline underlineColor underlineGapColor underlineGapOverprint underlineGapTint underlineOffset underlineOverprint underlineTint underlineType underlineWeight verticalScale warichu warichuAlignment warichuCharsAfterBreak warichuCharsBeforeBreak warichuLineSpacing warichuLines warichuSize xOffsetDiacritic yOffsetDiacritic
That's probably enough info for you to use ;)
" My current project requires a JPEG
export and an IDML (InDesign's package XML for 3rd parties) export and I cannot get the Dictionary standard "exports" to work."
Can you explain a bit more about what you call the standard exports to work? I *might* be able to help.
I had started writing a very simple parser for the sdef header file, but I never finished the project nor released my code since nobody seemed to need it. It would certainly be nice to have the equivalent of AppleScript Editor's dictionary viewer but with the MacRuby method names. It shouldn't be hard to do, but I really don't have much time to work on it at the moment. If anyone is interested, please let me know, I can assist you.
- Matt
p.s: To generate the bridgesupport file I run the following commands: $ sdef /Applications/Adobe\ InDesign\ CS5.5/Adobe\ InDesign\ CS5.5.app/ | sdp -fh --basename inDesign $ gen_bridge_metadata -c '-I.' inDesign.h > inDesign.bridgesupport
On Tue, Nov 1, 2011 at 9:42 AM, Spencer Rose <dspencerr@gmail.com> wrote:
Hey Matt,
Thanks for the response. I had already read and done the tutorial there. It was very helpful.
The problem is not so much the weakness of Scripting Bridge, it is the difficulty in knowing all of the method calls and their syntax available from InDesign.
Following an earlier thread in here i used "myIndesign.methods(true,true)" and now have a list of methods, but that list is completely devoid of really import actions like "open" & "export" and the documentation in the Scripting Dictionary for InDesign which I have been using for Javascript & Apple Script does not translate straight across. The code I used to start experimenting with speaking directly to the InDesign DOM and getting its info was as follows: @id = SBApplication.applicationWithBundleIdentifier('com.adobe.indesign') doc = @id.activeDocument
pgph = doc.allParagraphStyles
pgph.each do |style| puts "#{style.name}" puts style.appliedFont end
I get the name of the Paragraph Style, but the appliedFont just prints an SBObject.
This is a really small example, but is the basis for my work because I will need to get font names, styles, kerning, margins, the text of stories and coordinates of text boxes and a lot more information. My current project requires a JPEG export and an IDML (InDesign's package XML for 3rd parties) export and I cannot get the Dictionary standard "exports" to work. I really like macRuby and have totally jumped on it. Your book is awesome and has helped a ton. But I worry that it is not sufficiently evolved for me to use it on a project needing this level of control and access to InDesign
Thanks in advance, Spencer
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Incredible help, thanks so much Matt. This is a huge project for my company and willbe ongoing. There is a lot of information in your replies and I will probably spend a day or two working through a lot of it. I will most definitely be back to this post for more help however, and would be happy to help develop the parser/dictionary view as I get time and understand this a bit more. Anyway, I will be back to this post in the next few days when I have gained more understanding. The "exports" I am talking about are the methods to export pages to JPEG or to export an entire doc to IDML. I had previously done a lot of this in Javascript scripts using the ExtendScript editor to run them. Thanks again.
Did you get a bunch of errors like this: sdp: warning: skipping redeclared enumeration "inDesignOTpf" sdp: warning: skipping redeclared enumeration "inDesignJrua" when making your header? I am getting errors when making the header file, and I am sure that is the reason for errors when making the brigesupport file. I will do more research, just wondering.
Yes, I also saw these warnings (not errors). The header file and the bridgesupport look good here on Lion. I did some more tests and here is what I got: I was able to package the document with the following script: framework 'Foundation' framework 'ScriptingBridge' load_bridge_support_file 'inDesign.bridgesupport' app = SBApplication.applicationWithBundleIdentifier('com.adobe.indesign') doc = app.activeDocument doc.packageTo("/Users/mattetti/tmp/testPackage", copyingFonts:true, copyingLinkedGraphics:true, copyingProfiles:true, updatingGraphics:true, includingHiddenLayers:true, ignorePreflightErrors:true, creatingReport:true, versionComments:"this is a test", forceSave:true) # To generate a IDML (that seems to crash indesign after it's done) #app.generateIDMLSchemaTo("/Users/mattetti/tmp/idmlPackage", packageFormat:false) # I tried the following without success, probably because I don't know how the API works and how the export preset should be set :p page = doc.pages.first app.rasterizeDocumentPageDocument(doc, index:0, width:1024, height:768, to:"/Users/mattetti/tmp/page0.jpg", params:{}, cropBox: 0.2) page.asynchronousExportFileFormat("tagged text/PDF", to:"/Users/mattetti/tmp/page1.pdf", showingOptions: false, using: app.PDFExportPresets.first, versionComments: "test", forceSave: true) page.exportFormat("tagged text/PDF", to:"/Users/mattetti/tmp/page2.pdf", showingOptions: false, using: app.PDFExportPresets.first, versionComments: "test", forceSave: true) - Matt On Tue, Nov 1, 2011 at 4:50 PM, Spencer Rose <dspencerr@gmail.com> wrote:
Did you get a bunch of errors like this:
sdp: warning: skipping redeclared enumeration "inDesignOTpf" sdp: warning: skipping redeclared enumeration "inDesignJrua"
when making your header? I am getting errors when making the header file, and I am sure that is the reason for errors when making the brigesupport file. I will do more research, just wondering.
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Actually, when I build the bridgesupport file I get errors. ./inDesign.h:6176: error: duplicate declaration of method ‘-mergeWith:’ ./inDesign.h:6411: error: duplicate declaration of method ‘-mergeWith:’ a lot of them. There were 500+. After greping them and writing a script to remove those lines I got down to about 20 duplicates. I have spent a ton of time reading the header file and am nervous as to what is and is not necessary.
So I apologize for being such a pain, I appreciate the help though. I have tried everything and cannot get the bridgesupport file to generate on my machine at work which has Snow Leopard on it. I came home tonight and used my MacbookAir which has Lion on it, and it worked perfectly. Things are working much better. May come back with more questions, but this gives me the ability to at least make the basics work. Thanks again.
Your Snow Leopard machine needs to have the latest BridgeSupport installed: http://www.macruby.org/files/BridgeSupport%20Preview%203.zip Lion has the final version already installed. We added some more info on the website and we will hopefully deploy the updates soon when 0.11 goes live. - Matt On Wed, Nov 2, 2011 at 9:46 PM, Spencer Rose <dspencerr@gmail.com> wrote:
So I apologize for being such a pain, I appreciate the help though. I have tried everything and cannot get the bridgesupport file to generate on my machine at work which has Snow Leopard on it.
I came home tonight and used my MacbookAir which has Lion on it, and it worked perfectly. Things are working much better. May come back with more questions, but this gives me the ability to at least make the basics work. Thanks again.
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
So final question, now that I downloaded the updates to scripting bridge, and it compiles fine, I still get errors such as: `<main>': undefined method `exportFormat' this is right after running your "doc.packageTo" method which worked great. I got the exportFormat method and other methods I have tried directly from my indesign.spriptingbridge file. A few of the methods in there are working, most are giving me an "undefinded method" error. I think the error is because my parameter syntax is off. When I changed the parameter syntax on the one you made work I got the same error. So how do I know the right syntax? exportFormat: to: -showingOptions: using: versionComments: -forceSave: <arg type='B' index='2'/> -showingOptions: <arg type='B' index='5'/> -forceSave: packageTo: <arg type='B' index='1'/> - copyingFonts: <arg type='B' index='2'/> - copyingLinkedGraphics: <arg type='B' index='3'/> - copyingProfiles: <arg type='B' index='4'/> - updatingGraphics: <arg type='B' index='5'/> - includingHiddenLayers: <arg type='B' index='6'/> - ignorePreflightErrors: <arg type='B' index='7'/> - creatingReport: <arg type='B' index='9'/> - versionComments: <retval type='B'/> - forceSave: exportFormat:to:showingOptions:using:versionComments:forceSave: - packageTo:copyingFonts:copyingLinkedGraphics:copyingProfiles: - - updatingGraphics:includingHiddenLayers:ignorePreflightErrors: creatingReport:versionComments:forceSave: - 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? Thanks
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. :)
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-ma... 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 http://en.wikipedia.org/wiki/AppleScript#Open_Scripting_Architecture http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual... 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
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-ma...
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 http://en.wikipedia.org/wiki/AppleScript#Open_Scripting_Architecture http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual...
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
participants (2)
-
Matt Aimonetti
-
Spencer Rose