On Friday, December 16, 2011 at 10:17 AM, Stephen Horne wrote:
#!/usr/local/bin/macruby
framework 'Foundation'
framework 'ScriptingBridge'

# I followed Matt's instructions for making the bridge support file, but I wasn't sure where it needs to go, so I did this for a quick fix.
load_bridge_support_file '/Users/fatboy/inDesign.bridgesupport'

appurl = NSURL.fileURLWithPath("/Applications/Adobe Indesign CS5/Adobe InDesign CS5.app")
@id = SBApplication.applicationWithURL(appurl)
doc = @id.activeDocument

puts doc.name

pgph = doc.allParagraphStyles

pgph.each do |style|
     puts "#{style.name}"
     puts style.properties["appliedFont"].name
end



This code works, but it takes 15+ seconds to set up the link to InDesign (similar stuff with safari takes about 1 second, and in applescript or rb-appscript it takes about a tenth of a second for either InDesign or safari).

I also tried SBApplication.applicationWithBundleIdentifier("com.adobe.indesign"), and this was just the same.

Is there something I am missing here? 

I am afraid I don't have a copy of InDesign, so I cannot test your specific situation. However, it would be interesting to know what part of your script is slow. Specifically, I would be interested in seeing some benchmarking to indicate whether your script is wasting more time on the "load_bridge_support_file" line or the "SBApplication.applicationWithURL" line. (I suppose calls through to InDesign could be the bottle neck as well, but that would be rather unexpected I should think.)

You can probably start off with Ruby's Benchmark library (with some decent documentation here: http://rubydoc.info/stdlib/benchmark/frames , though honestly you only really need "Benchmark.measure"). From there it might be interesting to look at other profiling results, but best to start simple.

- Josh