I have the following script.
#!/bin/bash
#DATE=$(date +%F-%T)
select=$( echo -e "whole\narea\nwindow" | rofi -dmenu )
FILE_LOCATION=$(zenity --file-selection --save --confirm-overwrite --title="Save As")
if [[ $select == "whole" ]]; then
# gnome-screenshot -f ~/Pictures/Screenshot-$DATE.png
gnome-screenshot -f $FILE_LOCATION
elif [[ $select == "area" ]]; then
gnome-screenshot --area -f $FILE_LOCATION
elif [[ $select == "window" ]]; then
gnome-screenshot --window -f $FILE_LOCATION
fi
When I run the script, the dialog looks like:
However, it should look like:
I would also like to select the default file type as .png
.
How can I do that?
The solution I am currently using is:
#!/bin/bash
select=$( echo -e "whole\narea\nwindow" | rofi -dmenu )
function get_file_location() {
# Get last save directory location
if [[ ! -f "/tmp/kdialog_state" ]]; then
echo $HOME > /tmp/kdialog_state
fi
FILE_LOCATION=$(kdialog --getsavefilename "$(cat /tmp/kdialog_state)" "*.png")
FILE_LOCATION_TEMP=$FILE_LOCATION
}
function copy_image_to_clipboard() {
xclip -in -selection clipboard -target image/png
}
if [[ $select == "whole" ]]; then
maim --format=png | copy_image_to_clipboard
elif [[ $select == "area" ]]; then
maim --format=png --select | copy_image_to_clipboard
elif [[ $select == "window" ]]; then
maim --format=png --window=$(xdotool getactivewindow) | copy_image_to_clipboard
fi
get_file_location
xclip -selection clipboard -target image/png -out > $FILE_LOCATION
# save last used directory state
echo "${FILE_LOCATION%/*}" > /tmp/kdialog_state