koekeishiya / skhd

Simple hotkey daemon for macOS
MIT License
6.07k stars 204 forks source link

skhd does not run with zsh #290

Closed rijojohn85 closed 11 months ago

rijojohn85 commented 1 year ago

I tried for the longest time with zsh, but while running with skhd -V it kept saying

zsh:1: command not found: yabai

My path is correct. I started it with --start-service etc. Spent hours trying to make it work.

I finally tried running it with bash and it worked just right out of the box.

Have I done anything wrong?

My Path on bash is: /Users/rijojohn/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/rijojohn/Library/Android/sdk/platform-tools:/Users/rijojohn/flutter/bin

it is identical on zsh, I checked to be sure.

Is this a known issue?

tjex commented 1 year ago

in zsh, what is the output of which skhd and which yabai?

rijojohn85 commented 11 months ago

in zsh, what is the output of which skhd and which yabai?

which skhd: /opt/homebrew/bin/skhd which yabai: /opt/homebrew/bin/yabai

Sorry I didn't see a reply to this till now.

tjex commented 11 months ago

No worries. It would be good to look at your conf files for skhd and yabai. It may be down to a syntax issue. Also, be sure that the yabai scripting addition is setup correctly.

If you remove all yabai commands from skhd conf, do they function? In any case it sounds like skhd is actually working, and there's either a problem with yabai or your shell environment.

Can you call yabai manually from the shell? e.g. yabai -m query --windows

Fundamentally, as long as opt/homebrew/bin is in your zsh $PATH, then the yabai command should be found.

To be certain. Make sure to open a new shell window (not a tab) to check, or run exec zsh. Otherwise you'll be running the tests against old environment settings (e.g $PATH), as shell environment settings do not auto update / hot reload.

rijojohn85 commented 11 months ago

So the thing is, Yabai works. The windows are tiled and work well. skhd works, but only in bash. I can call yabai when the shell is set to zsh as well. I have another mac (Macbook Pro, Intel). On it Yabai and skhd work out of the box with zsh with no problems. I've done the script addition for yabai. Basically everything works with bash. This definitely is a shell issue. I am on a mac mini with m1. Does that make a difference? I checked the skhd plist file as well. That has /opt/homebrew/bin in the path as well:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.koekeishiya.skhd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/homebrew/bin/skhd</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/Users/rijojohn/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/rijojohn/Library/Android/sdk/platform-tools:/Users/rijojohn/flutter/bin</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
         <false/>
         <key>Crashed</key>
         <true/>
    </dict>
    <key>StandardOutPath</key>
    <string>/tmp/skhd_rijojohn.out.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/skhd_rijojohn.err.log</string>
    <key>ProcessType</key>
    <string>Interactive</string>
    <key>Nice</key>
    <integer>-20</integer>
</dict>
</plist>

I really don't know what the issue here is.

I use skhd only with yabai. So I don't know if anything else would work.

It's not really a big issue. It's just annoying me that I can't get this to work and that annoying message Apple sends to make me change my shell to ZSH.

tjex commented 11 months ago

I have another mac (Macbook Pro, Intel). On it Yabai and skhd work out of the box with zsh with no problems.

This further makes it seem like a problem with your zsh config and not a problem with skhd / yabai in general.

here is my skhdrc in case it gives you any clues as to a syntax issue in your conf.

You could add for example alt + cmd - 0x27 : open -a Dictionary # key = ' and see if that works for you. That is: alt + cmd - ' should open the Dictionary app. It's good to see if skhd is indeed working. Skhd should hot reload its config or you can do it manually skhd -r. You can also restart the service manually, skhd --restart-service.

Also have a look at the logs to see if there's any clues:

Without looking at your .zshrc and .zprofile it's hard to get any further ideas.

It could be worth looking at uninstalling skhd and reinstalling it while in a fresh zsh shell. Perhaps there are some directories that aren't being sourced after you've installed it via bash. That could be total nonsense - I'm not super clued up...

rijojohn85 commented 11 months ago

Okay so all other commands work. I think. Anyway you gave me an idea. I put the whole path for yabai in the skhdrc file and its all working. Oh well. I suppose its something. Thanks for the help :)

tjex commented 11 months ago

great :)

So if it works with a full path to the executable, but not just the name by itself; it would seem like there really is an issue with your shell environment for zsh.

That (loosley) means that the session / process that is running the skhd config file is actually not seeing your $PATH. (don't take this as lore - I'm not super in the know)

rijojohn85 commented 11 months ago

Yes, I figured that, but for the life of me, I can't figure out how to get that to work. Interestingly, when I run skhd as verbose (skhd -V) it works without the full path. But when I run run skhd with skhd --start-service it doesn't work. Oh well. Thanks for your help though :)

tjex commented 11 months ago

No worries.

Well, in case you come back to this in future, that would then suggest looking to see if there is something amiss with the launch agent file.

~/Library/LaunchAgents/com.koekeishiya.skhd.plist

It should be generated on install with the appropriate defaults (including paths). But considering there is something up with your zsh shell / user environment, that could also cause problems with the service.