da: (bit)
[personal profile] da
I will freely admit this post will be of limited interest, but I'm quite happy with this result, and maybe you will be too, if you're a big 'ol label-making geek. :)

So, part of GTD is the importance of having labeled manila file-folders. I can corroborate that printed-label folders do work better than hand-printed labeled folders. Not only do they look good, there's something viscerally fun about filing something away in a new folder.

The GTD guy recommends buying an electronic label-maker. For a number of reasons (including: the clutter factor, the expensive label-tape they use, and typing on those chiclet keyboards annoys me) I've made do with printing onto a sheet of Avery 3x10 labels in OpenOffice. While this solves those problems, this still felt like "making do" because it takes OpenOffice a full minute to open, the template is a little mis-aligned, yadda yadda.


My goal: a command-line tool to print labels in the proper format.

brian d foy wrote about perl and Avery labels some time ago, so I installed PostScript::MailLabels and gave it a whirl last night.

Wow that was easy.

Now I type into the shell:

~$ ~/bin/labeler
Project 1
Project 2
Project 3
^D


and Preview opens a .pdf with my three labels across the page. Running labeler 4x2 offsets to start at the 4th row and 2nd column (since I usually have incomplete sheets of labels to use up).

labeler full takes one label and makes a full sheet out of it.

Here's my code, based heavily on brian's:


#!/usr/bin/perl
# labeler.pl -- output postscript version of label text
# labeler.pl <position>
# labeler.pl <row>x<column>

# mostly stolen from brian d foy: 
# http://www.perlmonks.org/?node_id=413783

use strict;
use warnings;
use PostScript::MailLabels;

my $labels = PostScript::MailLabels->new;

my $position = shift || 1;
my $batch = 0;

if ($position =~ /(\d+)x(\d)/) {
    $position = (($1-1)*3 + ($2));
}

if ($position =~ /all/) {
    $position = $batch = 1;
}

die "Position must be a number or row and column (ex: 3x4)" unless 
    ($position =~/^\d+$/);
die "Position $position is greater than 30" unless ($position <= 30);

$labels -> labelsetup(
            Avery       => $labels->averycode(8160),
            PaperSize   => 'letter',
            Font        => 'Times-Roman',
	    FirstLabel  => $position,
            Y_Adjust    => 1 / 16,
            X_Adjust    => 1 / 16,
            );

$labels->editcomponent('first', 'name', 'no', 0 );
$labels->editcomponent('second', 'name', 'no', 1 );
$labels->editcomponent('third', 'name', 'no', 2 );
$labels->editcomponent('fourth', 'name', 'no', 3 );
$labels->editcomponent('fifth', 'name', 'no', 4 );

$labels->definelabel('clear');

$labels->definelabel(0,'first');
$labels->definelabel(1,'second');
$labels->definelabel(2,'third');
$labels->definelabel(3,'fourth');
$labels->definelabel(4,'fifth');
  
my $addresses = [ map { chomp; [ split /\\n/ ] } <> ];

if ($batch) {
    my @pattern = @$addresses;
    unshift @$addresses, @pattern foreach (1..29);
  }

print $labels->makelabels( $addresses );


This script will output warnings, and also needs the output data redirected to a file. So there's a tiny bash wrapper to do that, then open the file in Preview, which (oh by the way) auto-converts postscript to .pdf (which is a neat trick I didn't know before reading brian's post):


#!/bin/bash
/Users/daniel/work/labeler/labeler.pl $1 > /tmp/label.ps 2>/dev/null; open /tmp/label.ps




And that's my labeler, which I figure is at least 5 times cheaper than the tape-label machines, going by the price of the refills.

Data can come from a unix pipe or from standard input. Turning a manual task into a unix pipe command is about as good as it gets, productivity-improvement-wise. (assuming it's not a stupid task in the first place).

Oh and also, if we decide to do them this year, I think it will work wonderfully on holiday address labels, even straight from an emacs buffer of addresses, because you pipe data to it.

Date: Saturday, 22 November 2008 02:06 pm (UTC)
From: [identity profile] sulle-stelle.livejournal.com
LOVE it!

You are just the coolest!!!

Date: Sunday, 23 November 2008 04:10 pm (UTC)
From: [identity profile] da-lj.livejournal.com
*grin*

It's really too bad perl's tough for people; I want to wrap this up in a standalone .app to give away, but I don't know how :(

Date: Sunday, 23 November 2008 04:32 pm (UTC)
From: [identity profile] sulle-stelle.livejournal.com
Well, read some documentation and figure out how to make that .App!

Although, I would think that most everyone who uses emacs or whatever and uses the command line would probably know how to take your script and install it manually.

Date: Sunday, 23 November 2008 05:33 pm (UTC)
From: [identity profile] da-lj.livejournal.com
Hm, true; though lots of emacs users would never use cpan to install the library. *glances over at [livejournal.com profile] melted_snowball*

Oh! there's no reason it needs to be installed via CPAN; PostScript::MailLabels is precisely two library files with no dependencies. Bam, one zip-file later...

Hmm... guess this is one more task I could do :)

I'll get right on it, maybe next year. :)

Date: Sunday, 23 November 2008 05:48 pm (UTC)
From: [identity profile] sulle-stelle.livejournal.com
I had to download the developer tools to 'make' the CPAN module.

I have it all set up, but am bombing out at the conversion of the .ps to .pdf (Preview gives an error message). Hmmmm.....

Date: Sunday, 23 November 2008 06:10 pm (UTC)
From: [identity profile] sulle-stelle.livejournal.com
Console says that Preview says that the offending command is 'Font' (see below). But the 3 testfiles made during the CPAN module install process all open fine with Preview.


11/23/08 12:54:31 PM Preview[2705] PostScript conversion message: %%[ Error: undefined; OffendingCommand: Font ]%%

11/23/08 12:54:31 PM Preview[2705] PostScript conversion message: %%[ Flushing: rest of job (to end-of-file) will be ignored ]%%

11/23/08 12:54:31 PM Preview[2705] PostScript conversion message: %%[ Warning: PostScript error. No PDF file produced. ] %%

11/23/08 12:54:43 PM com.apple.launchd[84] (0x10c880.Locum[2767]) Exited: Terminated

Date: Sunday, 23 November 2008 08:09 pm (UTC)
From: [identity profile] da-lj.livejournal.com
Weird! Preview doesn't like a default font?!

How about this .ps file, http://coder.com/daniel/test.ps ?

That was produced by that CPAN module, using the same font my script does.

December 2024

S M T W T F S
12 34567
891011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Wednesday, 24 December 2025 11:33 am
Powered by Dreamwidth Studios