http://www.perlmonks.org?node_id=92404

I'm a Palm Pilot user. At work we use Windows NT and use MS Exchange/Outlook 97 for mail/PIM stuff. I like to copy files I am working on into Palm memos for review, so I wrote this script to automate this:
#!/usr/bin/perl -w # Takes the text file(s) specified on the command line and puts them # into Outlook notes. If you have a Palm pilot and use Chapura's # PocketMirror, then Outlook notes get copied into Palm memos when # you synchronise. use strict; use diagnostics; use Win32::OLE; use Win32::OLE::Const; die "This script is only good for Windows." unless ($^O eq "MSWin32"); my $Outlook; # Generally sunny, and naively optomistic. # Make sure we have Outlook, and that it is running. Chicken out if # either of these is not the case. eval {$Outlook = Win32::OLE->GetActiveObject('Outlook.Application')}; die "Outlook not installed." if $@; die "Outlook needs to be running." unless defined $Outlook; # Outlook OLE constants my $olc = Win32::OLE::Const->Load($Outlook); # We have to expand all wild-cards, because the Windows command shell # doesn't. We only want plain, text files, and we want to read them # whole, not a line at a time. @ARGV = map { glob } @ARGV; @ARGV = grep { -f && -T } @ARGV; undef $/; while (<>) { # New note for each file. my $note = $Outlook->CreateItem($olc->{olNoteItem}); # The Outlook note will consist of the filename followed by the file # contents. # The reason the note is prefixed with the filename is so that Palm # pilot can differentiate between them. If this wasn't done and, for # instance, this script was run on a group of Perl scripts (perl # txt2note.pl *.pl) then when these notes were synched to the Palm, # you would see a whole load of memos on your Palm entitled # "#!/usr/bin/perl -w". $note->{Body} = $ARGV . "\n" . $_; # Optional note properties. $note->{Categories} = "Business"; $note->{Width} = 800; $note->{Height} = 600; $note->{Top} = 20; $note->{Left} = 20; # Close and save note. $note->close($olc->{olSave}); }
I wrote the following Emacs lisp code in my _emacs file that runs the script on the current buffer:
;; Make F9 key copy the entire buffer to a new MS Outlook note (global-set-key [f9] ' copy-buffer-to-outlook-note) ; Copy entire buffer to MS Outlook note (defun copy-buffer-to-outlook-note () "Copy current buffer to MS Outlook note." (interactive) (shell-command-on-region (point-min) (point-max) "perl d:/perl/txt2n +ote.pl")))

Replies are listed 'Best First'.
Re: Outlook/Palm/PocketMirror users, take note...
by Anonymous Monk on Jun 29, 2001 at 17:17 UTC
    Oops, there is one too many close brackets at the end of the Emacs lisp code.
Re: Outlook/Palm/PocketMirror users, take note...
by John M. Dlugosz (Monsignor) on Jun 29, 2001 at 01:06 UTC
    I'll have to see if that works with my Pocket PC. It ought to, since Outlook gets synced including notes, normally. Thanks for posting that.
Re: Outlook/Palm/PocketMirror users, take note...
by perlmoth (Hermit) on Jul 08, 2003 at 18:15 UTC
    I have made some changes to help Palm III owners. The Palm III has a size limit on Memo files of 4 Kb. The following code will chop up large files into chunks of 4 Kb and create a separate Outlook note for each chunk, giving each a part number:


    #!/usr/bin/perl -w # Takes the text file(s) specified on the command line and puts them # into Outlook notes. If you have a Palm pilot and use Chapura's # PocketMirror, then Outlook notes get copied into Palm memos when # you synchronise. use strict; use diagnostics; use Win32::OLE; use Win32::OLE::Const; my $Outlook = get_outlook_handle(); # Outlook OLE constants my $olc = Win32::OLE::Const->Load($Outlook); # We have to expand all wild-cards, because the Windows command shell # doesn't. We only want plain, text files, and we want to read them # whole, not a line at a time. @ARGV = map { glob } @ARGV; @ARGV = grep { -f && -T } @ARGV; undef $/; while (<>) { # Code to chop up input files into 4000 byte blocks. Required # because of the Palm III's 4 Kb memo limit. if (length >= 4000) { my $counter = 1; my @part = /.{1,4000}/gs; foreach (@part) { my $title = "$ARGV part $counter"; create_outlook_note($title, $_); $counter++; } } else { create_outlook_note($ARGV, $_); } } sub get_outlook_handle { my $Outlook; # Make sure we are on windows die "This script is only good for Windows." unless ($^O eq "MSWin32" +); # Make sure we have Outlook, and that it is running. Chicken out if # either of these is not the case. eval {$Outlook = Win32::OLE->GetActiveObject('Outlook.Application')} +; die "Outlook not installed." if $@; die "Outlook needs to be running." unless defined $Outlook; return $Outlook; } # Create an Outlook note, putting the title on the first line of the # note sub create_outlook_note { my ($title, $body) = @_; # New note my $note = $Outlook->CreateItem($olc->{olNoteItem}); $note->{Body} = "$title\n$body"; # Optional note properties. $note->{Categories} = "Business"; $note->{Width} = 800; $note->{Height} = 600; $note->{Top} = 20; $note->{Left} = 20; # Close and save note. $note->close($olc->{olSave}); }



    Also, using the following Emacs lisp code in the _emacs file will call the program making sure the current buffer file name is put in the first line of the Outlook note:

    ;; Make F9 key copy the entire buffer to a new MS Outlook note (global-set-key [f9] ' copy-buffer-to-outlook-note) ; Copy entire buffer to MS Outlook note (defun copy-buffer-to-outlook-note () "Copy current buffer to MS Outlook note." (interactive) (shell-command (format "%s %s" "perl c:/perl/txt2note.pl" buffer-fi +le-name)))