Karabiner-elements: Remap Slack Command Enter

Created on 25 Sep 2016  Â·  38Comments  Â·  Source: pqrs-org/Karabiner-Elements

Hi,

I'd like to remap Command+Enter when using Slack.

Can this be done with Karabiner-Elements?

Here is a config from the old Karabiner...

<appdef>
    <appname>SLACK</appname>
    <equal>com.tinyspeck.slackmacgap</equal>
</appdef>

<item>
    <name>Slack Customisation</name>
    <item>
        <name>Map Cmd+Enter to send, Enter to extra line</name>
        <identifier>remap.app_slack_cmd_enter</identifier>
        <only>SLACK</only>
        <autogen>
            __KeyToKey__
            KeyCode::RETURN, ModifierFlag::COMMAND_L,
            KeyCode::RETURN
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::RETURN,
            KeyCode::RETURN, ModifierFlag::SHIFT_L
        </autogen>
    </item>
</item>

stale

Most helpful comment

I tried using Hammerspoon, but it's fairly painful.

I guess I can wait a bit.

Is app specific mappings reasonably high up on the development priority list?

All 38 comments

You can't do app specific mappings yet.

You can do this with Hammerspoon. An example: https://github.com/STRML/init/blob/master/hammerspoon/init.lua#L196

How do I sent the RETURN / ENTER key using hs.eventtap...

How do I change left-cmd + enter to enter?

I tried using Hammerspoon, but it's fairly painful.

I guess I can wait a bit.

Is app specific mappings reasonably high up on the development priority list?

Any improvement? When this feature will be back?
Thank you!

Apologies for the bump, but is there any sort of ETA on this particular feature?

I ended up building this myself tonight — it's a separate daemon, with right now no documentation, but if you're sufficiently technical, here you go:

https://github.com/nriley/Karabiner-Elements-App-Profiles

If a profile is named after an app's bundle identifier, it'll automatically switch to the profile when you bring that app to the front (and the first/default profile otherwise).

Obviously this would be better built into Karabiner-Elements!

Yes, please build something like this into Karabiner-Elements!
To try your version, should I just compile and run with Xcode?
(obviously not sufficiently technical ;-)

There are instructions in the README; if you have questions either post here or let me know. I just did a quick binary release so you don't need Xcode.

@nriley Excellent solution. Been waiting for a simple way to switch my ctrl/cmd key when in the remote desktop beta client and Parallels ever since upgrading to Sierra. Your solution works perfectly.

@nriley Thanks for the Binary release, will try it out, @planetscripton can you share your config please

@nriley this sounds great. Thanks for writing it up! Is there any chance we could get an example config file so that I know how to get this going?

Here is what I did to get it working (as far as I can recall)
Follow the link a few posts ago, and download the zipped file "Karabiner-Elements-App-Profiles.zip"
Follow the instructions in that zip file:

Copy the binary file "Karabiner-Elements-App-Profiles" to /usr/local/bin, you may need to create this folder (it seems like installing Wireshark creates this folder and installs wireshark binary links) or authenticate to copy into it.

Install the included launchd plist in ~/Library/LaunchAgents and load it
i.e. copy the file into that location and run the command
launchctl bootstrap gui/501 ~/Library/LaunchAgents/net.sabi.Karabiner-Elements-App-Profiles.plist
see https://babodee.wordpress.com/2016/04/09/launchctl-2-0-syntax/
Log-out and login again to test to works

Rename one or more Karabiner Elements profiles with apps' bundle identifiers
So I have profiles named
Default Profile
com.microsoft.rdc.osx.beta
com.barebones.bbedit
com.apple.Safari

And for example in Karabiner-Elements, under the com.microsoft.rdc.osx.beta profile I have keycaps to make:
Left Command => Left Control
Left Control => Left Command

Hope that helps
(set KE to display the menu bar icon so you can check what profile is active as you switch apps)

@mike-savory this works great! Thanks a lot for the explanation!

This was especially helpful - launchctl bootstrap gui/501 ~/Library/LaunchAgents/net.sabi.Karabiner-Elements-App-Profiles.plist

@mike-savory thanks for helping out!

I use my launch tool to get them; in Terminal type launch -f and drag an app onto the window, e.g.:

% launch -f /Applications/Mail.app 
/Applications/Mail.app: scriptable OS X application package 
    type: 'APPL'    creator: 'emal'
    display name: Mail
    architecture: Intel x86-64
    bundle ID: com.apple.mail

If you have Spotlight enabled you can also use mdls:

% mdls -name kMDItemCFBundleIdentifier /Applications/Mail.app 
kMDItemCFBundleIdentifier = "com.apple.mail"

@nriley launch works well. Thanks, and thanks for writing this up to allow per app settings!

I threw together a quick homebrew formula to simplify installing. Just install the karabiner-elements cask, then the tool that @nriley shared and add it to start up:

brew cask install karabiner-elements
brew install https://raw.githubusercontent.com/toonetown/homebrew-extras/master/Formula/karabiner-elements-app-profiles.rb
brew services start karabiner-elements-app-profiles

This works perfectly, thank you very much for putting the work to do this. I love open source community.

Working perfectly, thank you!

Anything new on this?

Now it is a default feature

In 0.91.13? How can I use it?

I am also curious as to how to use this feature on Karibiner elements. I'm not able to find it as a default feature. Could you please explain @LucaMarconato?
(I would like Karibiner elements automatically switch to one profile when I'm using Teamviewer [that switches the command and control keys] and another for all of my other applications)

Look at this link: https://github.com/tekezo/Karabiner-Elements/issues/808
I have based my karabiner.json file on transamericamoon one's and it is working.

Awesome. Thanks so much. I have it up and running. Now I just need to figure out how to tweak it so that it only runs when I'm typing from Teamviewer :) I'm a novice coder so I'm happy to have gotten as far as I have.

@LucaMarconato: Any changes I make to the script result in it not showing up in the Complex Modifications window in Karibiner Elements. Could you please tell me how I would tweak it so that the switch between keys only gets activated when Teamviewer is the front-most window?
(as of now, I can enable the original script and the command and control keys are switched in every application)

@garbage914, you can find my configuration here. Try replacing my bundle identifier with the one of TeamViewer. If it is switching the keys described in the file then you can try to put your keys and it should work.

@LucaMarconato Thank you so much for sending that. When I replace TeamViewer for Terminal, I get a "parse" error saying there's an unexpected '"' (unexpected quotation mark) and it doesn't make the changes in Terminal. If I run it without replacing teamviewer, your script runs perfectly and all works in Terminal.

@garbage914 I have found the documentation around configuration of complex modifications kind of lacking...but have somewhat been able to piece together a bunch of thoughts (and an example configuration that I use) here. Maybe it will help a bit?

I am new to the party.
@toonetown Can you verify with me that your solution ("configuration") does not require nriley's 3rd party daemon?

@LucaMarconato Why do you prepend a caret ('^') to the bundle_identifiers in your configuration?
e.g.,
"bundle_identifiers": [ "^org.gnu.Emacs", "^com.apple.Terminal" ],

Does anyone know if there is a frontmost_application_ifnot condition type (or something to that effect) available?

@nawkwan try with frontmost_application_unless

@toonetown Thank you so much for that. I actually got it working just before you sent that with this: https://forum.keyboardmaestro.com/t/switching-command-and-control-keys/7721/27?u=cinematree

Thank you to all who helped.

Hi guys, is there a way to work around with alfred? I have set to use hjkl in kindle with the frontmost_application_if approach, but I just found out that when such an app is in the front, the key remappings also cause typing hjkl in alfred to result as arrow keys.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

old thread here, but i use this script i wrote to swap profiles based on the current foreground app.
This basically allows you to create a json file of bundleNames -> karabiner profile names (including a default mapping)

Hope this helps someone

https://github.com/napisani/karabiner-profile-swapper

Sorry you had to spend the time writing that instead of using pretty much the same thing I wrote, which you can see linked above (https://github.com/pqrs-org/Karabiner-Elements/issues/137#issuecomment-277871527), just using Swift rather than PyObjC. These days I don't use it as I make individual modifications conditional with frontmost_application_if (example).

Should use the Complexity modification to achieve same result,

such as the Remote Desktop swap keys, can import the Complexity modification : https://ke-complex-modifications.pqrs.org/?q=remote%20desktop Virtual Machine and Remote Desktop (Microsoft or other) works on mac~

It is based on the https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/frontmost-application/

Was this page helpful?
0 / 5 - 0 ratings