Tell me more ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I created some services to be used in Finder. Now I wanted to create some keystrokes to call these services. That would be easy in the System Settings, however, I would like to add them from the command line in order to automate this setup.

I tried the following which did allow me not trigger the services by a keystroke:

defaults write com.apple.Finder NSUserKeyEquivalents '{ "label-red" = "$@1"; "label-green" = "$@2"; "label-none" = "$@0"; }'

Any ideas to make this work? Instead of com.apple.Finder I might have to use another identifier, but which?

share|improve this question

1 Answer

The enabled services and shortcuts are stored in ~/Library/Preferences/pbs.plist. Some of the default shorcuts are stored in ~/Library/Preferences/com.apple.ServicesMenu.Services.plist.

This prints the shortcut of an Automator service named test1 (there's no entry for it if it's enabled but doesn't have a shortcut):

/usr/libexec/PlistBuddy -c 'Print NSServicesStatus:"(null) - test1 - runWorkflowAsService":key_equivalent' ~/Library/Preferences/pbs.plist

This adds an entry (^~@t = ⌃⌥⌘T, see the Cocoa Text System article):

defaults write pbs NSServicesStatus -dict-add '"(null) - test2 - runWorkflowAsService"' '{key_equivalent = "^~@t";}'

To register the changes, run pbs -flush or log out and back in.

This enables a preinstalled service and assigns it a shortcut:

/usr/libexec/PlistBuddy -c 'Delete NSServicesStatus:"com.apple.systemuiserver - Open URL - openURL"' ~/Library/Preferences/pbs.plist; defaults write pbs NSServicesStatus -dict-add '"com.apple.systemuiserver - Open URL - openURL"' '{key_equivalent = "^~@u";}'; pbs -flush

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.