MacOS – How to map a Service’s Keyboard Shortcut on the Command Line

automatorkeyboardmacos

I'm trying to write a program that adds some new services to the Mac.

For this to work I need to add keyboard shortcuts to some installed services. Doing it though system preferences is not an option.

I need a command line operation that will let me map a keyboard shortcut to user created service.

Best Answer

The service shortcuts are stored in pbs.plist and can be modified like this:

/usr/libexec/PlistBuddy -c 'Delete NSServicesStatus:"(null) - \
  servicename - runWorkflowAsService"' ~/Library/Preferences/pbs.plist 2>/dev/null
defaults write pbs NSServicesStatus -dict-add '"(null) - \
  servicename - runWorkflowAsService"' \
  '{key_equivalent = "^~@1";}'

Source: https://apple.stackexchange.com/users/3936/

^ = control, ~ = alt, @ = command; replace servicename with the name of the service