36 lines
740 B
Shell
Executable file
36 lines
740 B
Shell
Executable file
#!/bin/sh
|
|
|
|
# Take a screenshot of the focused window
|
|
# (i.e., what "<Alt>Print" does)
|
|
#
|
|
# The screenshot machinery lives inside `gnome-shell`
|
|
# and cannot be called directly because
|
|
# its D-Bus methods are restricted to trusted callers
|
|
#
|
|
# => We synthesize the key press instead, after a short delay
|
|
# so that a launcher's keyboard grab (e.g., `rofi`) is released
|
|
|
|
set -eu
|
|
|
|
|
|
[ "${XDG_SESSION_TYPE:-}" = "x11" ] || {
|
|
echo "X11 only (xdotool)" >&2
|
|
exit 1
|
|
}
|
|
|
|
|
|
# Optional countdown in seconds (e.g., `screenshot-window 3`),
|
|
# defaulting to 0.2
|
|
countdown="${1:-0.2}"
|
|
|
|
case "$countdown" in
|
|
''|.|*[!0-9.]*|*.*.*)
|
|
echo "Not a number: $countdown" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
sleep "$countdown"
|
|
|
|
|
|
xdotool key alt+Print
|