Why don't my screenshot bindsyms work?

This one works:

#Select an area:
bindsym $mod+Control+i exec grim -g "$(slurp)" $HOME/Pictures/$(date +%Y%m%d-%H%M%S).png

But these don’t:
#Full screen with delay (for dropdowns):
bindsym $mod+Control+w sleep 10 && grim $HOME/Pictures/$(date +%Y%m%d-%H%M%S).png && paplay /usr/share/sounds/freedesktop/stereo/camera-shutter.oga

#Active window:
bindsym $mod+Control+a grim -g "$(swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"')" $HOME/Pictures/$(date +%Y%m%d-%H%M%S).png

If I exclude the bindsym bits, both codes work when pasted in the terminal.

I reloaded with $mod+Shift+c and didn’t get any swaynag messages/warnings.

Is grim a GUI or terminal program? If terminal you may need something like:

yourterminal -e yourcommand

But not a sway user :smiley:

It’s a terminal command. The GitHub page is here.

Got it! I think I forgot exec in two of the commands!!!

2 Likes

I know you forgot exec. :stuck_out_tongue_winking_eye:

1 Like

Ouch! But the active window one still doesn’t work. Must dig deeper …

This is what I have now:

#Full screen with delay (for dropdowns):
    bindsym $mod+Control+f exec sleep 10 && grim $HOME/Pictures/$(date +%Y%m%d-%H%M%S).png && paplay /usr/share/sounds/freedesktop/stereo/camera-shutter.oga
#Select an area:
    bindsym $mod+Control+i exec grim -g "$(slurp)" $HOME/Pictures/$(date +%Y%m%d-%H%M%S).png
#Active window:
    bindsym $mod+Control+a exec ~/.config/sway/scripts/active-window-screenshot.sh

I put the troublesome “Active window” one into a script:

#!/bin/sh

grim -g "$(swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"')" \
~/Pictures/$(date +%Y%m%d-%H%M%S).png && paplay /usr/share/sounds/freedesktop/stereo/camera-shutter.oga