0

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

如何将修饰符添加到击键命令?

4

1 回答 1

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 ])
于 2012-04-22T22:17:25.880 回答