解决方法
对于Mac:
gem install rb-appscript
然后你可以用这样的脚本测试它:
require "rubygems" require "appscript" include Appscript app("TextEdit").activate app("System Events").keystroke("Look Ma,keystrokes!")
对于Windows :(未经测试,borrowed from this thread)
require "win32ole" wsh = WIN32OLE.new("WScript.Shell") wsh.Run("Notepad.exe") while not wsh.AppActivate("Notepad") sleep .1 end wsh.SendKeys("Look Ma,keystrokes!")