koekeishiya / skhd

Simple hotkey daemon for macOS
MIT License
6.16k stars 205 forks source link

command using jq works when running from command line but not as a service #348

Open amuricys opened 6 months ago

amuricys commented 6 months ago

skhd-v0.3.9 yabai-v7.1.0

command in question

# create desktop, move window and follow focus - uses jq for parsing json
lshift + lcmd - n : yabai -m space --create && \
        index="$(yabai -m query --spaces --display | ~/.nix-profile/bin/jq 'map(select(."is-native-fullscreen" == false))[-1].index')" && \
        yabai -m window --space "${index}" && \
        yabai -m space --focus "${index}"

if I run skhd from a terminal, this command works correctly. but if I run skhd --start-service, it simply does not. I don't know where to look for logs either.

Note that if I comment out the index variable and set a literal index, like so:

lshift + lcmd - n : yabai -m space --create && \
        yabai -m window --space "5" && \
        yabai -m space --focus "5"

it works (assuming i only have 4 spaces)

MunsMan commented 5 months ago

It appears that the jq command is currently installed only in your user space and not system-wide. This could cause issues if you're trying to access it from processes that don't operate within your user environment, such as a daemon managed by launchd.

If you're using nix-darwin, I recommend installing jq system-wide by adding it to the environment.systemPackages in your Nix configuration. This will ensure it's available globally on your system.

Alternatively, if you prefer using Homebrew, you can install jq globally with the following command:

brew install jq

Please note that the path ~/.nix-profile/bin/jq is a dynamic symlink and might not be accessible to the skhd daemon when it's controlled by launchd, as these processes typically have different visibility into the file system than your user processes.