Last active
July 14, 2023 23:34
-
-
Save LeaPhant/b74d15af9749ad85e6e1a7d146dbe6bd to your computer and use it in GitHub Desktop.
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 | |
# screenshot.sh kde plasma wayland edition | |
# depends on imagemagick and spectacle | |
# Arch Linux: sudo pacman -Sy spectacle imagemagick | |
# usage: ./plasma-wayland-screenshot.sh (area|active|full) | |
# EDIT THESE | |
UPLOAD_URL="" | |
KEY="" | |
TYPE=${1:-"area"} | |
TMP_FILE="/tmp/Screenshot_$(date +'%y-%m-%d_%H-%M-%S').png" | |
JPG_TRESHOLD=600 # KiB | |
JPG_QUALITY=80 | |
THUMB_WIDTH=400 | |
THUMB_HEIGHT=160 | |
NOCONVERT=0 | |
if [ $TYPE == "area" ] | |
then | |
spectacle -brn -o "$TMP_FILE" | |
elif [ $TYPE == "active" ] | |
then | |
spectacle -ban -o "$TMP_FILE" | |
elif [ $TYPE == "full" ] | |
then | |
spectacle -bmn -o "$TMP_FILE" | |
elif [ $TYPE == "clipboard" ] | |
then | |
TMP_FILE="/tmp/Clipbard_$(date +'%y-%m-%d_%H-%M-%S').txt" | |
dbus-send --type=method_call --print-reply=literal --dest=org.kde.klipper /klipper org.kde.klipper.klipper.getClipboardContents | xargs > $TMP_FILE | |
NOCONVERT=1 | |
fi | |
FILESIZE=`wc -c <$TMP_FILE` | |
if [ $FILESIZE -ge 16 ] | |
then | |
if [ $FILESIZE -ge $((JPG_TRESHOLD * 1024)) ] && [ $NOCONVERT -eq 0 ] | |
then | |
NEW_FILE=`echo "${TMP_FILE::-4}.jpg"` | |
convert $TMP_FILE -quality $JPG_QUALITY $NEW_FILE | |
rm $TMP_FILE | |
TMP_FILE=$NEW_FILE | |
fi | |
URL=`curl -s -X POST $UPLOAD_URL -H "content-type: multipart/form-data" -F key=$KEY -F "file=@$TMP_FILE"` | |
dbus-send --type=method_call --dest=org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents string:"$URL" | |
notify-send 'Screenshot uploaded!' "URL" | |
rm $TMP_FILE | |
fi |
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 | |
# screenshot.sh wayland edition | |
# depends on imagemagick, wl-clipboard, grim and slurp | |
# (and optionally sway, which this script is optimized | |
# for and is needed for active window screenshot) | |
# Arch Linux: sudo pacman -Sy imagemagick wl-clipboard grim slurp | |
# only tested on Arch Linux with sway | |
# usage: ./wl-screenshot.sh (area|active|full) | |
# to use on sway with puush-like keybinds, add the following to | |
# ~/.config/sway/config (assuming this script is in path, e.g. ~/.local/bin) | |
# bindsym Control+Shift+2 exec wl-screenshot.sh active | |
# bindsym Control+Shift+3 exec wl-screenshot.sh full | |
# bindsym Control+Shift+4 exec wl-screenshot.sh area | |
# bindsym Control+Shift+5 exec wl-screenshot.sh clipboard | |
# EDIT THESE | |
UPLOAD_URL="" | |
KEY="" | |
TYPE=${1:-"area"} | |
TMP_FILE="/tmp/Screenshot_$(date +'%y-%m-%d_%H-%M-%S').png" | |
JPG_TRESHOLD=600 # KiB | |
JPG_QUALITY=80 | |
THUMB_WIDTH=400 | |
THUMB_HEIGHT=160 | |
NOCONVERT=0 | |
if [ $TYPE == "area" ] | |
then | |
if swaymsg &> /dev/null | |
then | |
# we are under a sway wm session, use better area selection | |
AREA=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | |
| .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp) | |
else | |
AREA=$(slurp -d) | |
fi | |
grim -g "$AREA" -t png "$TMP_FILE" | |
elif [ $TYPE == "active" ] | |
then | |
if swaymsg &> /dev/null | |
then | |
AREA=$(swaymsg -t get_tree | jq -r '.. | select(.focused?) | .rect | |
| "\(.x),\(.y) \(.width)x\(.height)"') | |
grim -g "$AREA" -t png "$TMP_FILE" | |
else | |
echo "active window capture only available on sway" | |
fi | |
elif [ $TYPE == "full" ] | |
then | |
grim -t png "$TMP_FILE" | |
elif [ $TYPE == "clipboard" ] | |
then | |
TMP_FILE="/tmp/Clipbard_$(date +'%y-%m-%d_%H-%M-%S').txt" | |
wl-paste -n > $TMP_FILE | |
NOCONVERT=1 | |
fi | |
FILESIZE=`wc -c <$TMP_FILE` | |
if [ $FILESIZE -ge 16 ] | |
then | |
if [ $FILESIZE -ge $((JPG_TRESHOLD * 1024)) ] && [ $NOCONVERT -eq 0 ] | |
then | |
NEW_FILE=`echo "${TMP_FILE::-4}.jpg"` | |
convert $TMP_FILE -quality $JPG_QUALITY $NEW_FILE | |
rm $TMP_FILE | |
TMP_FILE=$NEW_FILE | |
fi | |
URL=`curl -s -X POST $UPLOAD_URL -H "content-type: multipart/form-data" -F key=$KEY -F "file=@$TMP_FILE"` | |
echo -n $URL | xclip -selection clipboard | |
notify-send 'Screenshot uploaded!' "URL" | |
rm $TMP_FILE | |
fi |
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 | |
# depends on imagemagick, xclip, xdotool, kdialog and maim | |
# Arch Linux: sudo pacman -Sy imagemagick xdotool kdialog xclip maim | |
# only tested on Arch Linux with KDE | |
# usage: ./x-screenshot.sh (area|active|full) | |
# EDIT THESE | |
UPLOAD_URL="" | |
KEY="" | |
TYPE=${1:-"area"} | |
TMP_FILE="/tmp/Screenshot_$(date +'%y-%m-%d_%H-%M-%S').png" | |
JPG_TRESHOLD=600 # KiB | |
JPG_QUALITY=80 | |
THUMB_WIDTH=400 | |
THUMB_HEIGHT=160 | |
if [ $TYPE == "area" ] | |
then | |
maim -s "$TMP_FILE" | |
elif [ $TYPE == "active" ] | |
then | |
maim -i $(xdotool getactivewindow) "$TMP_FILE" | |
elif [ $TYPE == "full" ] | |
then | |
maim "$TMP_FILE" | |
elif [ $TYPE == "clipboard" ] | |
then | |
UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |
TMP_FILE="/tmp/$UUID.txt" | |
xclip -selection clipboard -o > $TMP_FILE | |
URL=`curl -s -X POST $UPLOAD_URL -H "content-type: multipart/form-data" -F key=$KEY -F "file=@$TMP_FILE"` | |
echo -n $URL | xclip -selection clipboard | |
rm $TMP_FILE | |
exit 0 | |
fi | |
FILESIZE=`wc -c <$TMP_FILE` | |
if [ $FILESIZE -ge 256 ] | |
then | |
if [ $FILESIZE -ge $((JPG_TRESHOLD * 1024)) ] | |
then | |
NEW_FILE=`echo "${TMP_FILE::-4}.jpg"` | |
convert $TMP_FILE -quality $JPG_QUALITY $NEW_FILE | |
rm $TMP_FILE | |
TMP_FILE=$NEW_FILE | |
fi | |
URL=`curl -s -X POST $UPLOAD_URL -H "content-type: multipart/form-data" -F key=$KEY -F "file=@$TMP_FILE"` | |
echo -n $URL | xclip -selection clipboard | |
convert $TMP_FILE -resize $THUMB_WIDTHx$THUMB_HEIGHT /tmp/screenshot_thumb.bmp | |
notify-send 'Screenshot uploaded!' '<img src="file:///tmp/screenshot_thumb.bmp" height="100%" alt="preview">' | |
# rm $TMP_FILE | |
echo $TMP_FILE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment