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

Applescript 使用rb appscript键入键盘快捷键,applescript,rb-appscript,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". --

我正在尝试使用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

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

解决方案是:

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