2012-04-22 55 views
0

我試圖用RB-appscript下面的腳本轉換爲Ruby的打字鍵盤快捷鍵:使用RB-appscript

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

怎麼辦我將這些修飾符添加到keystroke命令中?

回答

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