#!/usr/bin/perl use strict; use POSIX qw(strftime); =head1 DESCRIPTION Sends the contents of your X clipboard to your cellphone / PDA over Bluetooth. Using some regular expressions, it tries to guess the contents in order to make vCard entries where necessary. Very useful for quickly sending an address to the phone. Uses xclip and ussp-push (Bluetooth version). =cut ###################################################################### # edit these. my $rfcomm = "/dev/rfcomm5"; my $ussp_push = "ussp-push"; my $tmpdir = "/tmp"; ###################################################################### open XCLIP, "xclip -o|" or die "cannot pipe from xclip: $!"; my $xclip = join "", ; close XCLIP; my $to_send = $xclip; # common delimiters for phone numbers my $delim = qr/[.-\s]?/; my $phone_number = undef; # pull out the phone number if($to_send =~ s/^\s* ((?:\+1 $delim)? (?:\(\d{3,3}\)|\d{3,3}) $delim \d{3,3} $delim \d{4,4}) \s* $//xm ){ $phone_number = $1; } my $street = undef; # pull out an address, starting with the street. if($to_send =~ s/^\s* ( \d+ \s+ [\w\s.]+ ) \s* $//xm){ $street = $1; } my($city, $state, $zip); # pull out the city/state/zip part if( $to_send =~ s/^\s* (?:([\w\d-_ ]+)\, \s* (\w\w) \s+ )? (\d{5,5} (?:-\d{4,4})?)$//xm){ $city = $1; $state = $2; $zip = $3; } # kill whitespace $to_send =~ s/^\s*(.+?)\s*$/$1/s; print "phone number: $phone_number\n"; print "street: $street\n"; print "citystate: $city\n$state\n$zip\n"; print "rest: $to_send\n"; my $content; my $ext; if( $phone_number || $street ){ $content = generate_vcard( $to_send, $phone_number, $street, $city, $state, $zip ); $ext = "vcf"; }else{ $content = $xclip; $ext = "txt"; } my $filename = "clip2cell-".strftime( '%Y-%m-%d_%H:%M', localtime( time ) ).".$ext"; my $fullpath = "$tmpdir/$filename"; open OUT, ">$fullpath" or die "cannot open $fullpath for writing: $!\n"; print OUT $content; close OUT; system($ussp_push, $rfcomm, $fullpath, $filename ); unlink($fullpath); sub generate_vcard{ my @args = @_; # escape all the ; foreach my $arg (@_){ $arg =~ s/;/\\;/g; } my( $name, $phone, $street, $city, $state, $zip ) = @args; my $retval .=<