Skip to content

Instantly share code, notes, and snippets.

@ellcs
Created February 23, 2020 19:23
Show Gist options
  • Save ellcs/ab47127ab2991d40e6f6c741572bc5f0 to your computer and use it in GitHub Desktop.
Save ellcs/ab47127ab2991d40e6f6c741572bc5f0 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Copyright (c) 2020 ellcs.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# my i3 screenshot solution -- ellcs
#
# - x native, actually no i3 needed
# - screenshot focused window only
# - screenshot whole screen
# - give grepable names (time and name of window)
#
# It creates screeshots of the format "YYYY-MM-DD_dd:mm:ss_focused_window.png".
# You can bin it to i3 editing your .i3/config:
#
# bindsym $win+Shift+Return exec "/path/to/screenshot_i3.sh ALL"
# bindsym $win+Shift+s exec "/path/to/screenshot_i3.sh FOCUS"
#
# Make sure it's executable and edit the $screenshot_folder :)
screenshot_folder=/home/ellcs/Pictures/screenshots
mkdir -p "$screenshot_folder"
function currently_focused_window_id() {
echo "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')"
}
function currenty_focused_window_name() {
id=$1
echo $(xprop -id "${id}" | grep "WM_CLASS" | rev | cut -d" " -f1 | rev | cut -d'"' -f2)
}
function screenshot_whole_screen() {
window_id=$(currently_focused_window_id)
window_name=$(currenty_focused_window_name "$window_id")
date=$(date +%F_%T)
name=$(echo "${date}_${window_name}_whole.png")
echo $name > asdf
import -window root "${screenshot_folder}/${name}"
}
function screenshot_focused_window() {
window_id=$(currently_focused_window_id)
window_name=$(currenty_focused_window_name "$window_id")
date=$(date +%F_%T)
name=$(echo "${date}_${window_name}_single.png")
import -window "$window_id" "${screenshot_folder}/${name}"
}
[ $1 == "ALL" ] && screenshot_whole_screen
[ $1 == "FOCUS" ] && screenshot_focused_window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment