Reputation: 15
Is it possible to add KeyboardShortcuts in MacOs (Leopard) using shell or other programmatic way? Basically, something to automate the steps of opening Keyboard&Mouse in SystemPreferences, selecting the last tab "KeyboardShortcuts", Clicking "+" to add a new one and filling the info. Thank you
Upvotes: 1
Views: 104
Reputation: 15853
The following AppleScript should do the trick, with 3 variables:
app_name
: name of an application that you want to assign the shortcut to, e.g. Safarimenu_title
: exact menu name to executekeystrokes
: the actual shortcuttell application "System Preferences"
activate
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
tell process "System Preferences"
tell window "Keyboard"
click button 3 of tab group 1
tell sheet 1
click pop up button 1
click last menu item of menu 1 of pop up button 1
keystroke "/Applications/" & app_name & ".app"
keystroke return
keystroke return
delay 1
keystroke menu_title
keystroke tab
keystroke last item of keystokes using rest of reverse of keystokes
delay 1
click button "Add"
end tell
end tell
end tell
end tell
The code is referencing the following site: http://www.rngtng.com/2010/10/29/applescript-to-create-keyboard-shortcuts/
Upvotes: 2