Jan'uary » 日志 » Torsmo [I]
Torsmo [I]
Jan 发表于 2005-03-11 14:07:44
torsmo是一个类似于gdesklets的软件。在我的桌面上右边那个用来显示gmail/bloglines/weather的工具就是 torsmo. 我将会贴出一系列文章来说明torsmo的配置方法。简单的配置我就不说了,.torsmorc里面有很好的注释. 我想要说的是如何定制适合自己的个性化的torsmo.
torsmo的灵活性非常强,通过和定制脚本的配合可以做成许多事情。这里我贴出自己用的
几个脚本。我把这些脚本都放在~/.torsmo里面,而.torsmorc是~/.torsmo/torsmorc的一
个软链接。
首先是检查Gmail的新邮件信息的脚本,如果有新邮件,还可以显示出邮件标题。
~/.torsmo/gmail.pl: 通过Gmail的API得到邮箱状态信息
#!/usr/bin/perl
## gmail.pl
#find this two lib on CPAN
use Mail::Webmail::Gmail;
use GMail::Checker;
my greatest_ = "YOUR_ADDR"; # your Gmail username
my $password = "YOUR_PASS"; # your Gmail password
my $gmailfile = "/home/XXX/.torsmo/gmail.txt";
my $newmessages = 0;
my @subjects = ();
my $gwrapper = new GMail::Checker();
$gwrapper->login(greatest , $password);
my ($totalmessages, $usedspace) = $gwrapper->get_msg_nb_size();
$gwrapper->close();
my $gmail = Mail::Webmail::Gmail->new(username => greatest , password =>
$password, encrypt_session => 1);
my ($usage, $capacity, $usagep) = $gmail->size_usage();
my $messages = $gmail->get_messages(label => $Mail::Webmail::Gmail::FOLDERS{
'INBOX' });
foreach ( @{ $messages } ) {
if ( $_->{ 'new' } ) {
$newmessages += 1;
my $subject = $_->{ 'subject' };
$subject =~ s/<(.*?)>//gi; # remove tags
push(@subjects, $subject);
}
}
open(FD, "> " . $gmailfile) or die("Could not open file.\n");
print FD "totalmessages=" . $totalmessages . "\n";
print FD "newmessages=" . $newmessages . "\n";
print FD "status=Using " . $usage . " (" . $usagep . ") of " . $capacity . "\n";
for($i=0; $i<=$#subjects; $i++) {
print FD $subjects[$i] . "\n";
}
close(FD);
~/.torsmo/gmail_extract.pl: 提取信息的脚本,为torsmo所调用
#!/usr/bin/perl
# gmail_extract.pl
my $numArgs = $#ARGV+1;
if($numArgs != 1) {
die ("Usage error: gmail_extract.pl [info]\n");
exit;
}
else {
my $file = "/home/XXX/.torsmo/gmail.txt";
my $arg = $ARGV[0];
open (HANDLE, $file) or die ("Could not open file.");
@LINES = ;
if ($arg eq "newsubjects") {
$line = $LINES[1];
my ($foo, $newmessages) = split(/=/, $line);
if($newmessages > 0) {
for($i=3; $i<=$#LINES && $i < 12; $i++) {
my $num = $i-2;
my $sub = $LINES[$i];
# truncate long subjects so it will not
# autoexpand the tormso window
if(length($sub) >= 40) {
my $temp = substr($sub, 0, 40);
$sub = $temp . "...\n";
}
print " " . $num . ". " . $sub;
}
if($#LINES > 11) {
print " Check mailbox to see more ...";
}
}
}
# how many total message do I have?
if($arg eq "totalmessages") {
$line = $LINES[0];
my ($foo, $total) = split(/=/, $line);
$total =~ s/[\r\n]//g; # remove \n
print "There are " . $total . " messages\n";
}
# how many new messages do I have?
if($arg eq "newmessages") {
$line = $LINES[1];
my ($foo, $new) = split(/=/, $line);
$new =~ s/[\r\n]//g; # remove \n
if($new == 0) { print "There are no new messages\n"; }
elsif($new == 1) { print "There is one new message\n"; }
else { print "There are " . $new . " new messages\n"; }
}
# usage status
if($arg eq "status") {
$line = $LINES[2];
my ($foo, $retval) = split(/=/, $line);
# usage status
if($arg eq "status") {
$line = $LINES[2];
my ($foo, $retval) = split(/=/, $line);
print $retval;
}
close (HANDLE);
}
torsmo的灵活性非常强,通过和定制脚本的配合可以做成许多事情。这里我贴出自己用的
几个脚本。我把这些脚本都放在~/.torsmo里面,而.torsmorc是~/.torsmo/torsmorc的一
个软链接。
首先是检查Gmail的新邮件信息的脚本,如果有新邮件,还可以显示出邮件标题。
~/.torsmo/gmail.pl: 通过Gmail的API得到邮箱状态信息
#!/usr/bin/perl
## gmail.pl
#find this two lib on CPAN
use Mail::Webmail::Gmail;
use GMail::Checker;
my greatest_ = "YOUR_ADDR"; # your Gmail username
my $password = "YOUR_PASS"; # your Gmail password
my $gmailfile = "/home/XXX/.torsmo/gmail.txt";
my $newmessages = 0;
my @subjects = ();
my $gwrapper = new GMail::Checker();
$gwrapper->login(greatest , $password);
my ($totalmessages, $usedspace) = $gwrapper->get_msg_nb_size();
$gwrapper->close();
my $gmail = Mail::Webmail::Gmail->new(username => greatest , password =>
$password, encrypt_session => 1);
my ($usage, $capacity, $usagep) = $gmail->size_usage();
my $messages = $gmail->get_messages(label => $Mail::Webmail::Gmail::FOLDERS{
'INBOX' });
foreach ( @{ $messages } ) {
if ( $_->{ 'new' } ) {
$newmessages += 1;
my $subject = $_->{ 'subject' };
$subject =~ s/<(.*?)>//gi; # remove tags
push(@subjects, $subject);
}
}
open(FD, "> " . $gmailfile) or die("Could not open file.\n");
print FD "totalmessages=" . $totalmessages . "\n";
print FD "newmessages=" . $newmessages . "\n";
print FD "status=Using " . $usage . " (" . $usagep . ") of " . $capacity . "\n";
for($i=0; $i<=$#subjects; $i++) {
print FD $subjects[$i] . "\n";
}
close(FD);
~/.torsmo/gmail_extract.pl: 提取信息的脚本,为torsmo所调用
#!/usr/bin/perl
# gmail_extract.pl
my $numArgs = $#ARGV+1;
if($numArgs != 1) {
die ("Usage error: gmail_extract.pl [info]\n");
exit;
}
else {
my $file = "/home/XXX/.torsmo/gmail.txt";
my $arg = $ARGV[0];
open (HANDLE, $file) or die ("Could not open file.");
@LINES = ;
if ($arg eq "newsubjects") {
$line = $LINES[1];
my ($foo, $newmessages) = split(/=/, $line);
if($newmessages > 0) {
for($i=3; $i<=$#LINES && $i < 12; $i++) {
my $num = $i-2;
my $sub = $LINES[$i];
# truncate long subjects so it will not
# autoexpand the tormso window
if(length($sub) >= 40) {
my $temp = substr($sub, 0, 40);
$sub = $temp . "...\n";
}
print " " . $num . ". " . $sub;
}
if($#LINES > 11) {
print " Check mailbox to see more ...";
}
}
}
# how many total message do I have?
if($arg eq "totalmessages") {
$line = $LINES[0];
my ($foo, $total) = split(/=/, $line);
$total =~ s/[\r\n]//g; # remove \n
print "There are " . $total . " messages\n";
}
# how many new messages do I have?
if($arg eq "newmessages") {
$line = $LINES[1];
my ($foo, $new) = split(/=/, $line);
$new =~ s/[\r\n]//g; # remove \n
if($new == 0) { print "There are no new messages\n"; }
elsif($new == 1) { print "There is one new message\n"; }
else { print "There are " . $new . " new messages\n"; }
}
# usage status
if($arg eq "status") {
$line = $LINES[2];
my ($foo, $retval) = split(/=/, $line);
# usage status
if($arg eq "status") {
$line = $LINES[2];
my ($foo, $retval) = split(/=/, $line);
print $retval;
}
close (HANDLE);
}
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
