我的scrot截图脚本(自动上传imgur并复制链接)

效果: 调用后用鼠标选中一矩形区域, 截图后上传到imgur, 上传成功后复制图片的外链地址到剪贴板, 并弹出系统提示, 然后删除本地保留的临时图片文件.

脚本(其实就一行 – -)

sleep .1; scrot -bs -e 'curl -F "image=@$f" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml | grep -E -o "(.)*" | grep -E -o "http://i.imgur.com/[^<]*" | xclip -selection c; notify-send "Screenshot has successfully uploaded to `xclip -selection c -o`";rm -f $f' 2> ~/screenshoterr.log

注: 可以把这个脚本绑定到WM/DE的快捷键上, 比如我绑定的是类似QQ的 Ctrl+Alt+A
注2: 不加sleep .1的话, 用KDE快捷键绑定调用的时候存在时不时失灵的问题, 暂不知为什么, 其他环境未测试.

拆解一下scrot自动调用的部分:
上传图片:

  • curl -F "image=@$f" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml
    

提取图片直接外链地址

  • grep -E -o "(.)*"
  • grep -E -o "http://i.imgur.com/[^<]*"


输出链接到剪贴板

  • xclip -selection c

系统提示上传完成

  • notify-send "Screenshot has successfully uploaded to `xclip -selection c -o`"

删除本地文件

  • rm -f $f

Imgur的AppKey及此脚本主要部分来自: http://crunchbanglinux.org/forums/topic/11539/script-screenshot-upload-on-imgur-clickable-thumbnail/

5 thoughts on “我的scrot截图脚本(自动上传imgur并复制链接)”

  1. We’re really sorry, but anonymous uploading in your country has been disabled。
    悲剧啊 天朝啊。。。 你说肿么办

Leave a Reply

Your email address will not be published. Required fields are marked *

QR Code Business Card