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

yabai commands only work when skhd is run from terminal emulator #199

Closed
mlegls opened this issue Apr 8, 2022 · 18 comments
Closed

yabai commands only work when skhd is run from terminal emulator #199

mlegls opened this issue Apr 8, 2022 · 18 comments

Comments

@mlegls
Copy link

mlegls commented Apr 8, 2022

I installed the release version of both skhd & yabai from Homebrew on an M1 Macbook Air, running MacOS Monterey 12.3.1.

When running skhd from brew services start skhd, no yabai command shortcut works at all, but all other command shortcuts work fine.

However, the yabai commands themselves work fine from any terminal emulator, running either zsh or bash. Also, if I just start skhd directly from a terminal emulator rather than brew services, every yabai command shortcut works correctly.

@mlegls
Copy link
Author

mlegls commented Apr 8, 2022

@mlegls
Copy link
Author

mlegls commented Apr 8, 2022

In case someone else has the issue and this doesn't get an actual solution, my temporary workaround is just to use pm2 instead of brew services to run skhd as a daemon, and to start it on startup.

@marcelarie
Copy link

This happens to me too on a macbook m1 max.

@macalinao
Copy link

any updates here? this is pretty annoying

@marcelarie
Copy link

marcelarie commented Jul 8, 2022

pm2 was not working properly for me, so my workaround is the following:

  1. Open Automator
  2. Create an Application
  3. Search for "Run Shell Script" on the multiple options
  4. Write a script that adds the brew binaries to the path and runs skhd like this:
export PATH=/opt/homebrew/bin:$PATH;
skhd
  1. Save the Automator application on /Applications or wherever
  2. Go to System Preferences > Security and Privacy > Accesability
  3. Open the lock to make changes.
  4. Add the created Automator app to the list and enable it.
  5. Go to System Preferences > Users & Groups > Login Items
  6. Add the created Automator app there

🤯

Now after ALL this nonsense skhd is running on each startup, and yabai commands work. I tried launchctl but yabai commands did not work.

On the first try, instead of adding /opt/homebrew/bin to the PATH, Automator did not found skhd so I used directly the location of just the skhd binary (/opt/homebrew/bin/skhd) and this worked but, again, no yabai commands.

After adding the full path of homebrew binaries to the script, both work. I just say this because it might be the reason that brew service start does not, maybe it does not find yabai, but that does not make any sense.

Anyway, hope there is a solution for this soon, I miss my Linux.

Note:
Automator shows a small gear on the top bar when an app is running, if you want to hide that you can suppress the output of skhd in the script with &>/dev/null like this:

export PATH=/opt/homebrew/bin:$PATH;
skhd &>/dev/null;

@Gigibeau
Copy link

Gigibeau commented Jul 8, 2022

@marcelarie Thank you very much for this. I kinda gave up on the idea making it work with pm2 myself.

Small note on your note. The code block to prevent the gear icon didn't work for me. Instead, this worked:

export PATH=/opt/homebrew/bin:$PATH;
skhd &>/dev/null &

@es183923
Copy link

es183923 commented Aug 2, 2022

This issue is probably because skhd doesnt have the required permission. In a terminal, it may work, because the terminal was explicitly given the permission. Try opening the path of which skhd, and dragging it to the Security & Privacy->Privacy->Accessibility area in system preferences to grant it the permission.

@marcelarie
Copy link

@es183923 I gave explicit permissions as you said and the issue persists.

@es183923
Copy link

es183923 commented Aug 4, 2022

Did you try stopping the brew service, and starting it again? (brew services stop skhd && brew services start skhd)

@marcelarie
Copy link

marcelarie commented Aug 4, 2022

brew services stop skhd && brew services start skhd

Before trying it, the service was not running. I use the login item with Automator as I explained before, because some commands don't work if I run the service with brew.

So what I did is add the result of which skhd, in my case being /opt/homebrew/bin/skhd, to "...Privacy->Accessibility", as you explained, and then I started the service with brew. Of course, before all this, I deleted the Automator app from the login items. I restarted the laptop and skhd runs but without multiple commands, so it is the same.

Anyway, I tried running stop and start too, and it does the same thing.

Does it work for you? If it works, which Apple device are you using?

@es183923
Copy link

es183923 commented Aug 4, 2022

I don't know why it's not working for you. It has worked for probably thousands of people, except a certain few. If you're using an extremely old device, that could be why, but you seem to be using an Apple Silicon device. I'm using a 13" M1 Macbook pro.

Did you even start the service when trying the skhd commands?

Also, what commands are you referring to that "don't work"? It is very peculiar to have certain commands working, but not others.

@marcelarie
Copy link

I don't know why it's not working for you. It has worked for probably thousands of people, except a certain few. If you're using an extremely old device, that could be why, but you seem to be using an Apple Silicon device. I'm using a 13" M1 Macbook pro.

I use a macbook 14" M1 Ultra so I think it should work.

Did you even start the service when trying the skhd commands?

yes, tried it multiple times too.

Also, what commands are you referring to that "don't work"? It is very peculiar to have certain commands working, but not others.

yabai related commands. so skhd can run other commands but not the yabai ones.

@marcelarie
Copy link

marcelarie commented Aug 4, 2022

Ok I found the issue, thanks @es183923 because you are the reason I thought about it.

Basically for some reason brew service does not have the brew path.

My skhdrc file looked like this:

alt - k : yabai -m window --focus prev || yabai -m window --focus last
alt - j : yabai -m window --focus next || yabai -m window --focus first
shift + alt - q : skhd --key "cmd - w"

And I changed all the yabai and skhd commands for their absolute paths.

like this:

alt - k : /opt/homebrew/bin/yabai -m window --focus prev || /opt/homebrew/bin/yabai -m window --focus last
alt - j : /opt/homebrew/bin/yabai -m window --focus next || /opt/homebrew/bin/yabai -m window --focus first
shift + alt - q : /opt/homebrew/bin/skhd --key "cmd - w"

having to do this with each new command is not nice, but at least I am getting somewhere :)

@y-mx-b
Copy link

y-mx-b commented Sep 2, 2022

Ok I found the issue, thanks @es183923 because you are the reason I thought about it.

Basically for some reason brew service does not have the brew path.

My skhdrc file looked like this:

alt - k : yabai -m window --focus prev || yabai -m window --focus last
alt - j : yabai -m window --focus next || yabai -m window --focus first
shift + alt - q : skhd --key "cmd - w"

And I changed all the yabai and skhd commands for their absolute paths.

like this:

alt - k : /opt/homebrew/bin/yabai -m window --focus prev || /opt/homebrew/bin/yabai -m window --focus last
alt - j : /opt/homebrew/bin/yabai -m window --focus next || /opt/homebrew/bin/yabai -m window --focus first
shift + alt - q : /opt/homebrew/bin/skhd --key "cmd - w"

having to do this with each new command is not nice, but at least I am getting somewhere :)

I had the same issue and resolved it by moving my PATH additions to my .zshenv. I'm pretty sure the canonical macOS method would be to add a file to /etc/paths.d though; I haven't tried it yet, however, so I can't attest to whether it would work or not.

@XA21X
Copy link

XA21X commented Sep 13, 2022

Changing the skhd SHELL to /bin/bash surprisingly fixed this problem for me. Then I tried @y-mx-b's workaround which was also a success! 🎉

It turns out it's because I also have LnL7/nix-darwin installed...

For Zsh, it replaces the entire PATH via /etc/zshenv instead of appending to it, so the correct PATH override in the brew service got ignored. This is compounded by Homebrew expecting to get its PATH setup via ~/.zprofile, which is only sourced by login shells, but skhd runs commands like $SHELL -c $COMMAND. @y-mx-b's workaround works because ~/.zshenv is always sourced, including non-login shells.

For Bash, it also replaces the PATH, but it is instead done via /etc/bashrc, which is only sourced by interactive shells. The skhd command invocation creates neither a login nor interactive shell, so bash works because it avoids getting its inherited PATH overwritten.

tl;dr; nix-darwin + Zsh causes ignored PATH in the skhd brew service 😞

@y-mx-b
Copy link

y-mx-b commented Sep 14, 2022

Now that you mention it, this problem only cropped up for me after I installed Nix and Nix-Darwin... Damn.

@dakeryas
Copy link

dakeryas commented Jan 30, 2023

For Zsh, it replaces the entire PATH via /etc/zshenv instead of appending to it, so the correct PATH override in the brew service got ignored. This is compounded by Homebrew expecting to get its PATH setup via ~/.zprofile, which is only sourced by login shells, but skhd runs commands like $SHELL -c $COMMAND. @y-mx-b's workaround works because ~/.zshenv is always sourced, including non-login shells.

The issue is that OSX doesn't respect the contents of .zshenv by tampering with the PATH order (see https://apple.stackexchange.com/questions/432226/homebrew-path-set-in-zshenv-is-overridden), so putting exports in .zprofile was usually the solution as this was read last... Now the issue is that skhd can only access things from .zshenv... I tried hacking /etc/paths but that didn't seem to do the trick.

@sspaeti
Copy link

sspaeti commented Feb 15, 2023

The above solutions didn't work for me (MacBook m1 max, Ventura 13.1, using zsh, more). What did instead, was re-installing skhd under bash shell:

brew services stop skhd
brew uninstall skhd
SHELL=/bin/bash
brew install koekeishiya/formulae/skhd
brew cleanup skhd
brew services start skhd

I haven't restarted the machine yet; let's see if it persists in working :).

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

No branches or pull requests

10 participants