谨以此文献给深受阿姨广博且深邃文法毒害的同学.
切入正题, 由于下面的脚本涉及很多外部程序, 所以第一步先把依赖搞定:
$ sudo apt-get install scrot perl libwww-mechanize-perl xclip gnome-osd
第一个脚本. 截图并发送给贴图脚本.
$ cat capture_and_paste.sh
#!/bin/bash
cd /home/xiaogaozi/Picture/paste # 截图保存的文件夹
sleep 2 # 2秒后开始截图
scrot -sb -e '/home/xiaogaozi/Document/Perl/paste.pl $f'
exit 0
第二个脚本. 贴图脚本.
$ cat paste.pl
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
sub xclip
{
open(XCLIP, "|/usr/bin/xclip") or warn("No xclip - use .p\n"), return;
print XCLIP $_[0];
close XCLIP;
}
my $poster = "Dreamseeker"; # 张贴者
my $paste_url = 'http://paste.ubuntu.org.cn/';
my $screenshot = $ARGV[0];
my $mech = WWW::Mechanize->new();
$mech->get("$paste_url");
$mech->submit_form(
with_fields =>
{
"screenshot" => $screenshot,
"poster" => $poster
},
form_name => "editor",
button => "paste"
);
if ($mech->success())
{
my $rr = $mech->uri();
print($rr . "\n");
xclip($rr);
my $rrr = "贴图地址: " . $rr;
`/home/xiaogaozi/Document/ShellScript/osd_prompt.sh '$rrr'`; # 调用脚本用gnome-osd显示
}
else
{
`/home/xiaogaozi/Document/ShellScript/osd_prompt.sh "贴图失败"`; # 调用脚本用gnome-osd显示
print "ERROR:\t" . $mech->status() . "\n";
}
第三个脚本. 显示提示的脚本.
$ cat osd_prompt.sh
#!/bin/bash
gnome-osd-client -f "<message id='myplugin' osd_fake_translucent_bg='off'
animations='on' hide_timeout='2000' drop_shadow='off' avoid_panels='on'>
<span foreground='lightblue' size='large' weight='bold'>$*</span></message>"
最后只需执行第一个脚本就行了, 延时过了以后, 用鼠标拖动来截图, 也可以直接点击窗口截取整个窗口. 记得修改脚本中的路径.
No comments:
Post a Comment