我有下面的脚本。
#!/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当我运行脚本时,对话框如下所示:

然而,它应该看起来像:

我还想选择默认的文件类型为.png。
我怎么能这么做?
发布于 2022-08-01 09:19:16
我目前使用的解决方案是:
#!/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_statehttps://stackoverflow.com/questions/73032402
复制相似问题