1

I would like to use MacRuby with ScriptingBridge instead of AppleScript to control Mac applications which support AppleScript. I used to do this using appscript, which is effectively deprecated, hence the move the MacRuby and scripting bridge.

The only problem I have is that the ScriptingBridge framework takes about a second to load, even on a fast machine with a fast SSD. For example, this simple script takes about 0.9 seconds to run, with almost of the time spend loading the ScriptingBridge framework:

#!/usr/bin/env macruby

framework "ScriptingBridge"

textedit = SBApplication.applicationWithBundleIdentifier("com.apple.TextEdit")
textedit.activate

The equivalent osascript takes about 70 milliseconds to run, and py-appscript used to give similar times:

osascript -e 'tell application "TextEdit" to activate'

Is there any straightforward way to bundle/compile/shrink a MacRuby/ScriptingBridge script into something that starts more quickly?

I've tried using macrubyc to bundle the script into a standalone executable, but the resulting executable doesn't run much faster than the script when run normally, still taking about a second to run.

(My hunch is no, since a compilation step like macrubyc can't easily see which parts of the framework will be accessed by the script, making it hard to optimize.)

TheMaster
  • 45,448
  • 6
  • 62
  • 85
mattbh
  • 5,230
  • 2
  • 27
  • 27
  • For anyone interested, I found that the system Ruby (/usr/bin/ruby) loads the ScriptingBridge framework much more quickly (~200ms as opposed to ~900ms), so I'm using that instead. I'll leave the question open though, since my workaround doesn't address the original question. – mattbh Jan 30 '12 at 04:57

0 Answers0