1

I have the following script to set a services shortcut:

set serviceName to "(null) - VimAnywhere - runWorkflowAsService"
set libPrefPath to POSIX path of (path to preferences folder from user domain as text)
set plistFile to "pbs.plist"
set plistPath to libPrefPath & plistFile as text
set mainPropertyItem to "NSServicesStatus"
set keyBindingKey to "key_equivalent"
set keyBinding to "^@v"

tell application "System Events"
  set gp to (get property list item serviceName of property list item mainPropertyItem of property list file plistPath)
  tell gp
    set value of property list item keyBindingKey to keyBinding
  end tell
end tell

do shell script "defaults read > /dev/null"

This sets a keyboard shortcut for a service I have defined in the appropriated property list and it even displays properly when viewing in System Preferences. The problem is, the change doesn't seem to take effect. Invoking the keyboard shortcut has no effect.

How can I set this shortcut and have it take effect immediately (completely through shell/applescript)?

2

The changes made by the AppleScript are applied for me after I quit and reopen applications. Same for this command:

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

I don't know any way to apply the changes without reopening applications. Running /System/Library/CoreServices/pbs -flush or terminating pbs doesn't seem to work.

  • Which applications? This should be a system wide shortcut, so I'm not sure what I would have to do to get it to stick system wide. – Chris Knadler Jan 4 '14 at 7:40
  • 1
    I tested it with Preview, but it's probably the same for all applications. You can also just log out and back in or run sudo killall loginwindow. If it doesn't work at all, check if there is a menu item that has control-command-V as a shortcut. The shortcuts for menu items have precedence over the shortcuts for services. – Lri Jan 4 '14 at 8:07
  • It's every window. Once I close every window, it works perfectly. Thats so strange. Anyways, perfect answer! Thanks for all the help. – Chris Knadler Jan 4 '14 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .