使用rb-appscript键入键盘快捷键

时间:2012-04-22 21:26:24

标签: applescript rb-appscript

我正在尝试使用rb-appscript将以下脚本转换为Ruby:

-- Runs the keyboard shortcut for the provided application name.
-- applicationName - The name of the application to run the keyboard shortcut on.
-- key - The key to press.  For example, this could be "n" or "q".
-- modifiersList - A list of modifiers for the keyboard shortcut.  This could be something like
-- { command down } or { command down, shift down, option down }.
on runKeyboardShortcut(applicationName, key, modifiersList)
    tell application applicationName to activate
    tell application "System Events"
      keystroke key using modifiersList
    end tell
end runKeyboardShortcut

这是我到目前为止所拥有的:

def run_keyboard_shortcut(application_name, key, modifiers_list)
    Appscript.app.by_name(application_name).activate
    Appscript.app.by_name("System Events").keystroke(key)
end

如何将修改器添加到击键命令?

1 个答案:

答案 0 :(得分:0)

解决方案是这样做:

def run_keyboard_shortcut(application_name, key, modifiers)
    Appscript.app.by_name(application_name).activate
    Appscript.app.by_name("System Events").keystroke(key, :using => modifiers)
end

run_keyboard_shortcut("Finder", "n", [ :command_down ])