Tuesday, March 14, 2006

The End of my AppleScript Lines

Several years ago I worked for Independent Newspapers in Johannesburg. One of my most challenging and successful projects involved placing ads on the editorial pages, and drawing the lines around the ad boxes.
On Friday I was chatting to Mahomed Doola at The Star and discovered to my delight (and horror) that my program is no longer being used, and their entire editorial process in being upgraded and replaced by some really exciting technology.
I was the "resident propellor-head" in the IT Department at the time, and we were using QuarkXPress for page layouts. Every day a dozen or so highly paid sub-editors would waste several hours of their time drawing empty boxes on their pages where the ads should go, and then spending even more time drawing visible lines ("rules") around these boxes to separate the ads from the editorial copy. It was a mindless and boring task, and if it was done in too much of a hurry it made the pages look dreadful.
On top of that, the people in the advertising department who decided where the ads were to go would have to do a long manual task of drawing and labeling the ad boxes on page dummies, and then send a photocopy of the dummy to the sub-editors to draw the ad boxes on their pages.
We solved the ad placement problem with a nifty but expensive program (PlanLinker) from PCS in the UK. It allowed the advertising department to create the boxes directly from the list of ads and their sizes, and this page information was then "checked in" to the editorial system in a way that allowed the editorial people to see the shapes of the ads, and eventually include the ads on the pages, without them doing a whole lot of extra work.
Part of this "checking in" process was automated by means of some AppleScript programs, and it included the program for drawing the lines around the boxes.
The Algorithm
It was so simple once I got it, but it took several days of drawing lines and boxes to figure out what was required. After all, the ad boxes could be stacked on top of one another, or next to one another, or both. As long as they were generally to the bottom and the outside part of the editorial pages, there wasn't much else to go on. The task was to find a way of drawing a line between the "staircase" of ads and the editorial copy. And then there were lines to be drawn between the ads as well.
After a while it dawned on me that irrespective of how complicated the layout of the ads was, there was always a line to be drawn above the ad, unless the ad hit the top of the page. Also, the horizontal line always had to extend out beyond the top of the ad. This distance was always the same: half the gutter width. If the ad was on the outside of the page, then the line didn't need to extend at all, since there was no gutter margin on the outside, only between columns.
So now I had a line above every ad. I soon realized that if there were two ads next to one another of the same height, the lines would touch, giving the appearance of a solid line. Also, I now had horizontal lines between all the ads as well, because the line above an ad at the bottom of the page would work as the line between it and the ad above it.
Using the same logic I could draw a vertical line on the inside of every ad. If the page was a left hand page, i.e. with an even number, this line would be on the right of the ad, and for odd numbered pages on the left. The lines were left out if they extended beyond the page margins.
If I kept the vertical gap between ads the same size as the gutter width, then all the lines would be half that distance away from the ad itself, leaving a nice clean geometry around the ad.
It took a while to learn how to do all of this using AppleScript, and I got ideas and code from a number of very helpful people on the AppleScript email list. It was a wonderful learning experience.
The AppleScript program was in use for around 10 years, which is a long time for a utility like that. It was fun while it lasted.

No comments:


Warning: The NSA and 4 million other sick weirdos with "security clearance" have intercepted this page and know that you are reading it.