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

痞子三分冷 提交于 2019-12-23 04:19:35

问题


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

来源:https://stackoverflow.com/questions/8830436/is-it-possible-to-reduce-the-startup-time-of-macruby-scripts-which-use-the-scrip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!