You are not logged in.
Thought to share here for those that may want different scrot options from a single keybind using a yad dialog.
This script presents five options that can be scrolled from the keyboard, with the screenshot saved to ~/Pictures/scrot/date... showing exact time. The dialog closes on selection so not in the screenshot. The "selection" and "Copy Select" option allows either a button click on any open window, or selection by creating the size yourself.
Current options are:
- No Delay
- 5 Seconds
- Selection
- Copy Full
- Copy Select
Requires yad, xclip, and libnotify-bin. Most likely, these are already installed. can check with:
apt policy yad xclip libnotify-bin
#!/bin/bash
#
# Use scrot with different options and have yad close on click.
# Requires yad, xclip, libnotify-bin
#
## Add functions
NOW(){
# Use printf to store the current date/time as variables.
printf -v date "%(%F)T"
printf -v time "%(%I-%M-%S)T"
# Create primary and secondary directories
DIR="$HOME/Pictures/Scrot"
if ! test -f "$DIR"; then
mkdir -p "$DIR"
fi
mkdir -p "${DIR}/${date}"
# cd to directory and screenshot with time attached
cd "${DIR}/${date}" || exit
SCR="${DIR}/${date}/${date}-${time}.png"
scrot -m "$SCR"
notify-send --urgency low " Saved screenshot as ${SCR/*\/}"
}
LATER(){
# Use printf to store the current date/time as variables.
printf -v date "%(%F)T"
printf -v time "%(%I-%M-%S)T"
# Create primary and secondary directories
DIR="$HOME/Pictures/Scrot"
if ! test -f "$DIR"; then
mkdir -p "$DIR"
fi
mkdir -p "${DIR}/${date}"
# cd to directory and screenshot with time attached
cd "${DIR}/${date}" || exit
SCR="${DIR}/${date}/${date}-${time}.png"
scrot -md 5 "$SCR"
notify-send --urgency low " Saved screenshot as ${SCR/*\/}"
}
CAPTURE(){
# Use printf to store the current date/time as variables.
printf -v date "%(%F)T"
printf -v time "%(%I-%M-%S)T"
# Create primary and secondary directories
DIR="$HOME/Pictures/Scrot"
if ! test -f "$DIR"; then
mkdir -p "$DIR"
fi
mkdir -p "${DIR}/${date}"
# cd to directory and screenshot with time attached
cd "${DIR}/${date}" || exit
SCR="${DIR}/${date}/${date}-${time}.png"
scrot -s "$SCR"
notify-send --urgency low " Saved screenshot as ${SCR/*\/}"
}
COPY(){
# Use printf to store the current date/time as variables.
printf -v date "%(%F)T"
printf -v time "%(%I-%M-%S)T"
# Create primary and secondary directories
DIR="$HOME/Pictures/Scrot"
if ! test -f "$DIR"; then
mkdir -p "$DIR"
fi
mkdir -p "${DIR}/${date}"
# cd to directory and screenshot with time attached
cd "${DIR}/${date}" || exit
SCR="${DIR}/${date}/${date}-${time}.png"
scrot -e 'xclip -selection clipboard -t image/png -i $f' "$SCR"
notify-send --urgency low " Saved screenshot as ${SCR/*\/}"
}
COPYSEL(){
# Use printf to store the current date/time as variables.
printf -v date "%(%F)T"
printf -v time "%(%I-%M-%S)T"
# Create primary and secondary directories
DIR="$HOME/Pictures/Scrot"
if ! test -f "$DIR"; then
mkdir -p "$DIR"
fi
mkdir -p "${DIR}/${date}"
# cd to directory and screenshot with time attached
cd "${DIR}/${date}" || exit
SCR="${DIR}/${date}/${date}-${time}.png"
scrot -e 'xclip -selection clipboard -t image/png -i $f' -scapture "$SCR"
notify-send --urgency low " Saved screenshot as ${SCR/*\/}"
}
## Export functions
export -f NOW
export -f LATER
export -f CAPTURE
export -f COPY
export -f COPYSEL
yad --title "Scrot" --escape-ok \
--button=gtk-cancel:0 --form --center --geometry=210x304-314-60 --borders=10 \
--text="" --text-align=center --on-top --close-on-unfocus \
--window-icon=applications-utilities \
--form --columns=1 \
--field=" No Delay!/usr/share/icons/hicolor/16x16/apps/org.xfce.screenshooter.png:FBTN" 'bash -c "NOW & kill $YAD_PID"' \
--field=" 5 Seconds!/usr/share/icons/hicolor/16x16/apps/org.xfce.screenshooter.png:FBTN" 'bash -c "LATER & kill $YAD_PID"' \
--field=" Selection!/usr/share/icons/hicolor/16x16/apps/org.xfce.screenshooter.png:FBTN" 'bash -c "CAPTURE & kill $YAD_PID"' \
--field=" Copy Full!/usr/share/icons/hicolor/16x16/apps/org.xfce.screenshooter.png:FBTN" 'bash -c "COPY & kill $YAD_PID"' \
--field=" Copy Select!/usr/share/icons/hicolor/16x16/apps/org.xfce.screenshooter.png:FBTN" 'bash -c "COPYSEL & kill $YAD_PID"'
So, anyone can easily add as many options as desired, and just change the columns in the yad dialog if needed.
For the script, every function is currently complete within itself. I was unable to get a "main" function to work correctly, so not quite as easy to add options as it could be.
Last edited by sleekmason (2023-11-28 18:25:50)
Offline
Nice.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline