首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zenity显示打开而不是保存对话框

Zenity显示打开而不是保存对话框
EN

Stack Overflow用户
提问于 2022-07-19 06:55:29
回答 1查看 34关注 0票数 0

我有下面的脚本。

代码语言:javascript
复制
#!/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

我怎么能这么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-01 09:19:16

我目前使用的解决方案是:

代码语言:javascript
复制
#!/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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73032402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档