Is it possible to reduce the startup time of MacRuby scripts which use the ScriptingBridge?

233 views Asked by At

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.)

0

There are 0 answers