Skip to content

Instantly share code, notes, and snippets.

@kaushikgopal
Last active May 16, 2024 00:57
Show Gist options
  • Save kaushikgopal/ff7a92bbc887e59699c804b59074a126 to your computer and use it in GitHub Desktop.
Save kaushikgopal/ff7a92bbc887e59699c804b59074a126 to your computer and use it in GitHub Desktop.
My source Karabiner file in Goku's edn format - Now lives @ https://github.com/kaushikgopal/dotfiles/blob/master/.karabiner.edn
;; File has moved over to https://github.com/kaushikgopal/dotfiles/blob/master/.karabiner.edn
;; Feel free to raise github issues in that repo, if you have questions/comments/edits
@njm2112
Copy link

njm2112 commented Apr 17, 2020

I'm having some difficulty implementing layer/simlayer functionality and wondered if you have any advice.

I am trying to create "o-mode" whereby pressing the letter o performs the typical behavior, but holding o and pressing another key executes a Keyboard Maestro macro. Here's an excerpt from my Karabiner.edn file:

:layers { :o-mode {:key :o} }

:simlayers {
    :caps-mode { :key :escape :alone { :key :escape :condi ["caps-mode" 0]}}
    :launch-mode { :key :caps_lock} },

    :main [
        {:des "o-mode -> Hold o + key" :rules [
            [:g [:km "Search using Google"]] [:o-mode] ]}       ;; pressing `g` while holding `o` triggers KM macro

        {:des "w-mode -> Hold w + key" :rules [
            [:left_arrow [:!CTOSleft_arrow] [:w-mode]]          ;; pressing `←` while holding `w` triggers `⌘⌃⌥⇧`  + `←`
            [:right_arrow [:!CTOSright_arrow] [:w-mode]]]} }    ;; pressing `➝` while holding `w` triggers `⌘⌃⌥⇧` +  `➝`

The trouble I'm having is that once I implement this and trigger "o-mode" once (o +g), it seems that I'm stuck in o-mode and everytime I press g (including in isolation), the Keyboard Maestro macro is triggered.

Is there something obvious about my config (that I'm missing) that is causing this behavior? Any insight you might have would be appreciated.

@kaushikgopal
Copy link
Author

@njm2112 so i definitely do something very similar so surprised it isn't working for you.

Can you rewrite your script like so:

:layers { :o-mode {:key :o} }
...
:main [

{:des "o-mode: quick open applications"
 :rules [:o-mode
            [:g [:km "Search using Google" ] ] ;; pressing `g` while holding `o` triggers KM macro
]}

That should do the trick. I have something like this and it works like a charm:

image

image

@einverne
Copy link

It seems these two lines have a syntax error:

       [:!Ww :!TOSdelete_or_backspace !:terminals]
       [:!Tw :!TOSdelete_or_backspace !:terminals]

Should it be :!terminals?

@kaushikgopal
Copy link
Author

@einverne: right you are. i'll go ahead and update the script. that's a typo.

@hugows
Copy link

hugows commented May 11, 2022

I'm seeing your blog post only now :) Why so many commented shortcuts, are they failing you?

@hugows
Copy link

hugows commented May 11, 2022

For any other brave soul arriving here: layers is about HOLDING the first key and then typing the next one. For some reason (muscle memory), I was simply typing the keys in fast sequence (trying to implement some kind of open-mode)

@kaushikgopal
Copy link
Author

I'm seeing your blog post only now :) Why so many commented shortcuts, are they failing you?

no they are not. i actively like to try different combinations and after i try them out for sometime, comment if i decided i don't need it, or don't like it.

i also keep some of them to remind me how to implement some of those shortcuts.

@elmart-devo
Copy link

elmart-devo commented Feb 12, 2023

Hi, I'm getting a stack overflow trying to run this on brew-installed goku in MacOS Ventura 13.0.

Exception in thread "main" java.lang.StackOverflowError
	at com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError0(StackOverflowCheckImpl.java:328)
	at com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError(StackOverflowCheckImpl.java:324)
	at com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.throwNewStackOverflowError(StackOverflowCheckImpl.java:304)
	at clojure.lang.LazilyPersistentVector.createOwning(LazilyPersistentVector.java:25)
	at clojure.lang.RT.vector(RT.java:1609)
	at clojure.lang.Tuple.create(Tuple.java:26)
	at karabiner_configurator.core$exit.invokeStatic(core.clj:32)
	at karabiner_configurator.core$exit.invoke(core.clj:31)
	at karabiner_configurator.core$exit.invokeStatic(core.clj:32)
	at karabiner_configurator.core$exit.invoke(core.clj:31)
	at karabiner_configurator.core$exit.invokeStatic(core.clj:32)
	at karabiner_configurator.core$exit.invoke(core.clj:31)
	at karabiner_configurator.core$exit.invokeStatic(core.clj:32)
	at karabiner_configurator.core$exit.invoke(core.clj:31)
	at karabiner_configurator.core$exit.invokeStatic(core.clj:32)
	at karabiner_configurator.core$exit.invoke(core.clj:31)
	at karabiner_configurator.core$exit.invokeStatic(core.clj:32)

Any idea if it's this file's problem or goku problem?
I would say it's goku's problem (it seems the exit function is calling itself endlessly on error).

@joshuawagner
Copy link

Exception in thread "main" java.lang.StackOverflowError
at com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError0(StackOverflowCheckImpl.java:328)

I'm getting the same error. Did you figure out a solution to this @elmart-devo or anyone?

@elmart-devo
Copy link

I opened this issue at goku: yqrashawn/GokuRakuJoudo#211.
There is a commit there fixing it, but AFAIK there's no public release including it.

@joshuawagner
Copy link

I opened this issue at goku: yqrashawn/GokuRakuJoudo#211. There is a commit there fixing it, but AFAIK there's no public release including it.

Turns out that I had an issue with my karabiner.edn file (or maybe I hadn't created it yet at that point). I have it working now. If it isn't working for you, maybe check that you have the file in the specified location and that you have a 'main' section in your karabiner.edn file.

Here's what mine currently looks like.
https://gist.github.com/joshuawagner/b6d53fba5e361906f38832feee027cb3

@kaushikgopal
Copy link
Author

hey folks, moving this file over to my dotfiles repo. figured it'll be easy to just raise issues etc. and track better there.

@kaushikgopal
Copy link
Author

@joshuawagner @elmart-devo 🤔 that's interesting. i haven't run into that specific issue. hopefully it's now resolved?

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