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

Remap Slack Command Enter #137

Closed
SwimGeek opened this issue Sep 25, 2016 · 38 comments
Closed

Remap Slack Command Enter #137

SwimGeek opened this issue Sep 25, 2016 · 38 comments
Labels

Comments

@SwimGeek
Copy link

SwimGeek commented Sep 25, 2016

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>
@talha131
Copy link
Contributor

You can't do app specific mappings yet.

@STRML
Copy link

STRML commented Sep 25, 2016

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

@SwimGeek
Copy link
Author

SwimGeek commented Sep 25, 2016

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

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

@SwimGeek
Copy link
Author

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?

@LucaMarconato
Copy link

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

@NJAldwin
Copy link

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

@nriley
Copy link

nriley commented Feb 7, 2017

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!

@mike-savory
Copy link

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 ;-)

@nriley
Copy link

nriley commented Feb 15, 2017

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.

@planetscripton
Copy link

@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.

@mike-savory
Copy link

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

@kkuhle
Copy link

kkuhle commented Apr 27, 2017

@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?

@mike-savory
Copy link

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)

@kkuhle
Copy link

kkuhle commented Apr 28, 2017

@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

@nriley
Copy link

nriley commented Apr 28, 2017

@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"

@kkuhle
Copy link

kkuhle commented Apr 29, 2017

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

@toonetown
Copy link

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

@lidraro
Copy link

lidraro commented Jun 26, 2017

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

@LucaMarconato
Copy link

Working perfectly, thank you!

@3rd3
Copy link

3rd3 commented Aug 29, 2017

Anything new on this?

@LucaMarconato
Copy link

Now it is a default feature

@3rd3
Copy link

3rd3 commented Aug 30, 2017

In 0.91.13? How can I use it?

@garbage914
Copy link

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)

@LucaMarconato
Copy link

Look at this link: #808
I have based my karabiner.json file on transamericamoon one's and it is working.

@garbage914
Copy link

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.

@garbage914
Copy link

@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)

@LucaMarconato
Copy link

LucaMarconato commented Sep 2, 2017

@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.

@garbage914
Copy link

@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.

@toonetown
Copy link

@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?

@nawkwan
Copy link

nawkwan commented Sep 7, 2017

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" ],

@nawkwan
Copy link

nawkwan commented Sep 7, 2017

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

@LucaMarconato
Copy link

@nawkwan try with frontmost_application_unless

@garbage914
Copy link

@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.

@hiecaq
Copy link

hiecaq commented Dec 2, 2017

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.

@stale
Copy link

stale bot commented Mar 3, 2018

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.

@stale stale bot added the stale label Mar 3, 2018
@stale stale bot closed this as completed Mar 10, 2018
@napisani
Copy link

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

@nriley
Copy link

nriley commented Jul 30, 2020

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 (#137 (comment)), just using Swift rather than PyObjC. These days I don't use it as I make individual modifications conditional with frontmost_application_if (example).

@xinatcg
Copy link

xinatcg commented Dec 3, 2020

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/

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

No branches or pull requests