Oh, you know…you’re hanging out with buddies or talking to relatives and they ask what you do or they’re all telling tales of what happened to them at work or someone asks you how your day went, so you say:
well, maybe you do that once or twice, but the glazed eyes and the rapid interruptions sort of teach you not to do that. So unless you hang out with other programmers, you hardly ever get to talk about your day or share what you just pulled off that you’re feeling fantastic about, and it gets kind of isolating.
So…how about in here? I assume we’ll still have to break things down for each other and supply necessary background information at times, but I figure we stand a better chance of understanding what other programmers are talking about at least in general terms than other people would be.
Today I finished setting up a FileMaker database system to the specifications of our in-house client. The project had been discussed in terms of “some time in the next six months we’re definitely going to have to try to see if we can do that, whenever we get the time”, and I did it in 2 days, which makes our department look nice…what they wanted was: they had an existing FileMaker database that had fields in each record describing the size in height and width of a graphic image; actually each image had up to three separate height and width parameters, the “bleed” area (outside of which anything should be cut and discarded), “trim” area (down to which additional trimming CAN occur), and “safety” area (within which all the text is to be confined, since PostScript text sometimes doesn’t align with the graphic image when printed the way it shows on screen, so this is a safety margin for the text). Another field indicated which server was to hold the overall folder for the project. What they wanted was to be able to click a button and have folders appear on the appropriate server, named for the project and the account, and, within those folders, a series of subfolders with names like “mechanicals”, “accounting”, etc; and then they wanted a QuarkXPress document to come into being, sized about 4 inches taller and 2 inches wider than the largest of the height and width parameters, and in that document, boxes outlining the bleed (if present in this particular project), trim (if present), and safety (if present), with crop marks and guides, and a descriptive text box (9 point Helvetica, center-justified) centered below where the image goes, providing name, date, creator, project name, size, and other information; and this QuarkXPress document should save itself in the “mechanicals” folder of the project-account folder that had just been created, with the name of the Quark document being the job number + project name. Oh, and it should avoid overwriting any existing document of that name at that location.
It works rather nicely! FileMaker has calculation fields; the contents are the results of the formula entered in the Field Definition. One possible type of calc field is type “text”. I wrote a set of calc fields of this type each of which has as its results the complete text of an AppleScript command. One tells the Finder to make the folders in the appropriate place and give them the appropriate names, trapping for error (Finder will not not overwrite an existing folder with that command and will issue an error instead) and reporting that the folder already exists if an error is trapped; one tries to open the Quark document at the designated location, trapping for error (Finder issues an error if file not found) and continuing only if an error is encountered; one tells Quark to create a new document and size it, and put in three boxes (Bleed, Trim, Safety) and size them, and draw crop marks and add guides, then draw the text box and enter the text, size it and justify it, then save it to the correct location; and a handful of variations on that one handle records that lack a bleed parameter or one of the other parameters. (The main script branches with an IF statement).
An AppleScript is generally chock-full of quotation marks, like so:
meanwhile, FileMaker field defs require non-numerical constants to be offset in quotation marks, so if you want a field’s actual value to be “The Straight Dope Message Board”, that’s exactly how you would write it in the field def, quotation marks and all. So if FileMaker encounters a second quotation mark anywhere after a first, it assumes this is the end of the string, so some interesting tricks were necessary to enclose quoted text as part of the field definition itself. First a field was defined as “”"", which FileMaker evaluates as meaning the field has as its contents the string: " (yeah, a quotation mark). That lets me:
The paragraph symbols are interpreted by FileMaker as carriage returns and the &-marks mean “and” in the sense of concatenation as opposed to trying to add terms together.
Then in the Filemaker script, I just say “Perform Applescript [the text of which is in that field right there]” and point it at the field I defined. Is that cool or what?
(I’ve done it with HTML code too, and exported web pages and instructed Netscape to load them after export).