Words of occasional wisdom from Bruce Oakley


Links: Tips-Traps | Change Case | Parse Data | Search-Replace

About scripts

I love to make machines do my work for me, and I like to share ideas so that others can consider the possibilities of working smarter. The titles on the descriptions below are links to pages outlining some of the things I have learned. These pages provide commented AppleScript workhorse routines that should be of use in all kinds of projects and should migrate well to various word processing applications. These were written for a program called NewsEdit from MediaSpan Media Software, but only a few lines of each would need to be modified to work in other applications. Most of them started as Apple-supplied routines for Finder tasks. Each entry includes suggested enhancements that might be useful and should be simple to script, even for newbies. Nowadays, with Apple’s Automator, development should be easier still.

These scripts were developed during my nine years as editor of Arkansas Online, the Web site of the Arkansas Democrat-Gazette. I have been teaching newsroom machines to do my work with varying degrees of success since 1980, with projects in AppleScript, BASIC, php and perl, with occasional forays into VBScript and Javascript. My AppleScripts drive applications including Bare Bones Software’s BBEdit (and its freeware sibling TextWrangler), Apple TextEdit and Mail, and Microsoft’s Word, Entourage and Outlook Express.

About safety and liability

These samples are guides to basic scripting and the author will not be held liable for any damages arising from their use. The code is presented so that it can be copied and pasted into a Script Editor window, but as with any copy and paste, you should check for unintended line breaks or mistranslated special characters. Some of the lines may be longer than the browser window, so you may want to stretch it to check. In my own projects, most of my scripts make copies of source files and work on the copies. I generally turn automation loose only on duplicates. These sample routines are running on Mac OS X, through version 10.4.

Tips and Traps

Purpose: Save time and trouble with a few tips on traps to avoid in your scripting. Sad to say I learned about most of them the hard way in years of refining my scripts.

Change Case script

Purpose: Change case of selected text to all upper, all lower, cap first letter of each word. Most word processing programs provide some sort of facility to do this, but this combines multiple options in one window and the general technique may be used to alter other text attributes.
Operates on: A selection in the frontmost editing window.

Parse Delimited Data script

Purpose: Parse data in a delimited text file and reformat.
Operates on: Story in the frontmost editing window.
Suggested uses: Pliable script can be customized in short order for converting any statistical material into plain-English format, with string manipulation, date conversion, calculations and rearrangement of fields. Turn spreadsheet or database records into print listings and encode specialized typography as needed.

Search-Replace script

Purpose: Performs multiple search and replace from a list of standard search-replace pairs (useful for style enforcement or translation from outside sources).
Operates on: Full text of the frontmost editing window.
Suggested uses: Any material that takes repetitive cleanup, such as horoscopes, bridge columns, sports statistics, court filings, bankruptcy listings. Expansion or abbreviation in addresses: Road to Rd., Avenue to Ave. Style cleanup: AM or PM to a.m. or p.m. Removing zeros from times: :00 p.m. to p.m.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: