Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate setting a default keyboard shortcut in OSX #1

Closed
cknadler opened this issue Dec 30, 2013 · 8 comments
Closed

Automate setting a default keyboard shortcut in OSX #1

cknadler opened this issue Dec 30, 2013 · 8 comments
Assignees

Comments

@cknadler
Copy link
Owner

Upon running the install script, a default keyboard shortcut should be set for invoking vim-anywhere on OSX.

I have absolutely no idea how to do this.

@cknadler
Copy link
Owner Author

cknadler commented Jan 1, 2014

Opened a question on stack exchange and threw up a bounty.

http://apple.stackexchange.com/questions/115675

@cknadler
Copy link
Owner Author

cknadler commented Jan 2, 2014

Found some great resources and made general progress.

First of all, the property list that contains this shortcut is pbs:

$ defaults read pbs
{
    NSServicesStatus =     {
        "(null) - VimAnywhere - runWorkflowAsService" =         {
            "key_equivalent" = "@^v";
        };
        "org.vim.MacVim - MacVim/New MacVim Buffer Here - newFileHere" =         {
            "enabled_context_menu" = 0;
            "enabled_services_menu" = 0;
        };
    };
}

Now, being as this is a nested property list, it isn't really easy to edit it via the command line. Even if you read the entire property as it is now, process it and modify it, writing it back becomes another problem.

Apparently, you can also do this in pure applescript (which terrifies me, but I'm going to give it a shot).

scpt way: https://discussions.apple.com/thread/4709713?tstart=0

@ghost ghost assigned cknadler Jan 2, 2014
@cknadler
Copy link
Owner Author

cknadler commented Jan 3, 2014

Something like:

set theServiceName to "(null) - Print to PDF - 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 theKey to "key_equivalent"

tell application "System Events"

    set gp to (get property list item theServiceName of property list item mainPropertyItem of property list file PlistPath)

    tell gp
        --set value of property list item "enabled_services_menu" to true
        --set value of property list item "enabled_context_menu" to true
        set value of property list item theKey to "@^h"

    end tell

end tell

do shell script " defaults read " & quoted form of PlistPath

though I can't exactly get this to work.

@cknadler
Copy link
Owner Author

cknadler commented Jan 4, 2014

@cknadler
Copy link
Owner Author

Would be over the moon if anyone could figure this one out. I never could quite get it to work on OSX.

@jgrasser
Copy link

jgrasser commented Feb 17, 2018

Enabling the shortcut via System Preferences results in this entry appearing in the Mac OS X user defaults system :

$ defaults read pbs
{
    NSServicesStatus =     {
        "(null) - VimAnywhere - runWorkflowAsService" = {
             "key_equivalent" = "@^v";
        };   
        "org.vim.MacVim - MacVim/New MacVim Buffer With Selection - openSelection" =         {
            "key_equivalent" = "@^v";
        };
    };
}

You can add this manually by running the following:

$ defaults write pbs NSServicesStatus '{     
        "(null) - VimAnywhere - runWorkflowAsService" = {
             "key_equivalent" = "@^v";
        };                                                                 
        "org.vim.MacVim - MacVim/New MacVim Buffer With Selection - openSelection" =         {
            "key_equivalent" = "@^v";
        };
  }'

Is this an acceptable solution? I am not entirely familiar with MacOSX so this answer might be incomplete, or incorrect.

@cknadler
Copy link
Owner Author

Following up in #74.

@cknadler
Copy link
Owner Author

Closed by #74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants