Created
February 9, 2021 17:43
-
-
Save jameds/55bf048f0014ef4cc822c4643ee195b9 to your computer and use it in GitHub Desktop.
Screenshot i3 window by name, including decoration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# i3 window snapshotting tool | |
# Screenshot tools can't seem to grab i3 window decorations (even if they grab | |
# the window borders). So I wrote this piece of shit to do it. It even focuses | |
# the window before taking a picture! -a bird | |
type i3-msg xdotool jq import >/dev/null || exit 1 | |
die() {>&2 echo "$*" ; exit 1 ;} | |
i3-msg -q || die "No i3 socket?" | |
[ -z "$1" ] && die "$0 window title" | |
[ -t 1 ] && die "PIPE THIS COMMAND" | |
ogid=$(xdotool getactivewindow) | |
read -d '' -r magic <<'EOT' | |
..|.nodes?|.[]?|select(.window != null)|select(.window_properties.title | |
|test($title))|.output,.window,.deco_rect.height,(.rect|values[]) | |
EOT | |
< <(i3-msg -t get_tree | jq -r --arg title "$*" "$magic") readarray -t g | |
wksp="$(i3-msg -t get_outputs | jq --arg output "${g[0]}" \ | |
'.[]|select(.name==$output)|.current_workspace')" | |
i3-msg -q "[id=${g[1]}] focus" | |
g="${g[5]}x$((g[6] + g[2]))+${g[3]}+$((g[4] - g[2]))" | |
import -silent -window root -crop "$g" png:- | |
i3-msg -q "workspace $wksp ; [id=$ogid] focus" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment