menu Chancel's blog
rss_feed
Chancel's blog
有善始者实繁,能克终者盖寡。

LinuxGnome截图脚本(自动复制到粘贴版)

作者:Chancel Yang, 创建:2021-12-06, 字数:1539, 已阅:90, 最后更新:2021-12-06

这篇文章更新于 862 天前,文中部分信息可能失效,请自行甄别无效内容。

最近更新到Gnome41版本,结果截图插件再次崩溃了,不得不说第三方插件虽然功能丰富但稳定性真是堪忧

Gnome自带截图程序 gonme-screenshot 简单强悍,非常好用,而且通常不会因为Gnome版本更新崩掉

缺点是只能保存为文件,虽然命令行中有 -c Send the grab directly to the clipboard 参数可选,但我加了-c剪贴板粘贴完全无效..

只有文件的话截图之后分享不是很方便,就考虑写一个bash脚本,利用xlicp将截图之后的照片直接发送到粘贴版

于是有了以下这个脚本

Bash
#!/bin/bash
# author:chancel
# url:https://chancel.me

show_help() {
    echo "$0 [-h|-?|--help] [--temp /tmp/_backup] [--target /opt/backup/] [--dbuser root] [--dbpasswd passwd] [--extra /opt]"
    echo "-h|-?|--help    显示帮助"
    echo "-folder   截图保存文件夹"
    echo "-select default area 截图方式(area/window/full)"
}
select=area

while [[ $# -gt 0 ]]; do
    case $1 in
    -h | -\? | --help)
        show_help
        exit 0
        ;;
    -folder)
        folder="${2}"
        shift
        ;;
    -select)
        select="${2}"
        shift
        ;;
    --)
        shift
        break
        ;;
    *)
        echo -e "错误: $0 无效操作 '$1'\n可输入命令 '$0 --help' 获取更多帮助.\n" >&2
        exit -1
        ;;
    esac
    shift
done

filename=$folder/$(date +%Y%m%d)_$(date +%H%M%S).png
if [ $select == "area" ]
then
    gnome-screenshot -a --file=$filename
elif [ $select == "window" ]
then
    gnome-screenshot -w --file=$filename
else
    gnome-screenshot --file=$filename
fi
xclip -selection clipboard -t image/png -i $filename

使用方法1:用鼠标截取想截图的部分

Bash
bash screenshot.sh -folder /tmp -select area

使用方法2:截图当前活动Window

Bash
bash screenshot.sh -folder /tmp -select window

参数说明

  • folder:截图文件存放位置
  • select:截图方式(area/window/full)

截图后会按时间在指定文件夹生成截图文件并复制到粘贴版


[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]