Agregue mediante programación un método abreviado de teclado a las preferencias del sistema de Mac

If I go to System Preferences, Keyboard, Keyboard Shortcuts, then Application Shortcuts, I can define custom shortcuts to be used on a Mac.

Any way to access this functionality via Applescript?

preguntado el 28 de agosto de 11 a las 05:08

3 Respuestas

The shortcuts are stored in NSUserKeyEquivalents dictionaries in ~/Library/Preferences/.GlobalPreferences.plist and the property lists of applications.

defaults write -g NSUserKeyEquivalents -dict-add Duplicate '~@d' Minimize '\0'
defaults write com.apple.finder NSUserKeyEquivalents '{"Show Package Contents"="@\r";}'

The shortcut format is described in the Sistema de texto de cacao artículo.

Respondido el 01 de diciembre de 12 a las 18:12

System Preferences isn't scriptable with Applescript natively, you have to interact with it by Secuencias de comandos de GUI. GUI Scripting is really a last resort that allows you to interact with controls by explicitly declaring and calling them, and it doesn't take much to throw off a GUI script. It is difficult to implement even for experienced Applescript programmers. You'll find a few tutoriales introductorios out there in the web, but not much else.

Respondido 28 ago 11, 14:08

System Preferences does have a basic dictionary, but you can't modify individual preferences without System Events. Many preferences (like Application Shortcuts) can be edited in property lists though. - Lri

@Lri: True, but as you point out "...you can't modify individual preferences without System Events." Thus making it such that Apple shouldn't even have bothered. - Philip Regan

The internals of the Mac OS are quickly becoming a lost art. Run the following in a shell, or run via shell in Applescript:

defaults write com.google.Chrome NSUserKeyEquivalents '{ "Search the Web…" = "@k"; }'

Respondido 28 ago 11, 20:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.