Skip to main content

Scripting Better Writing

Most writers develop patterns in their prose. Experts can use these patterns to calculate the likelihood that a given text was written by a particular author. For example, my weaknesses include "unfortunately" and "just." President Obama overuses the phrase, "Let me be clear." Does the president need our permission to be clear? I doubt anyone tries to obstruct presidential clarity.

Since buying my first copy of WordPerfect for DOS, I've maintained macros to help locate and remove my personal textual demons. The idea is simple: automatically highlight the words and phrases I might want to revise before submitting the text to an editor. Four years ago, a student noticed the red words in an open Word document on my laptop. She asked if the highlighting was part of Word's grammar or spellcheck features. I explained to her that when I finish writing a document I run several macros to mark potential problems.

When the student asked for a copy of the macro, I was confronted with what I call the "spellcheck" question: Does automatic "editing" help students?

There is a pedagogical concern when automating tasks associated with editing and revising. Teachers ask me if the automation leads to "laziness" among writers. I do not believe so. Using automation to highlight my weaknesses has helped me avoid the words and phrases during the writing process. In many ways, the word processor is acting as a coach. The macro I use does not change my words, nor does it suggest changes. Instead, I must decide if the highlighted words should be changed or removed. Sometimes, I leave the original words.

My students have found that customizing the macro for their individual writing patterns helps them discover patterns they didn't suspect existed. There are ways to generate "word frequency" tables, showing students which words they use most in a text. The frequency charts reveal "lots" of "really" abused words. Students are fascinated by this. The idea that a writer has a unique "voice" magically registers with students at that moment.

I am not opposed to automating editing tasks. No statistics instructor I know would oppose using Microsoft Excel macros. Creating the macros requires understanding the underlying concepts. A student has to understand what an adverb is and does before appreciating why some adverbs are "weak" word choices.

Below you will find the AppleScript I use when writing. When Microsoft shipped Office 2008 for the Mac, I had to convert my simple Visual Basic for Applications (VBA) macro to AppleScript. This conversion was also an opportunity to add functionality to the macro. I've been asked to cut word counts, reduce complexity, and target a broader audience. I added Word functions that help me meet the requirements of my editors.
Note: The AppleScript Editor has moved several times in OS X. In 10.6, the editor is located in the "Utilities" folder. You can use Spotlight to find the AppleScript Editor, if all else fails.
If you use MS Word for the Mac, the script I crafted can be copied and saved to the following folder:
~/Documents/Microsoft User Data/Word Script Menu Items/
-- Mark likely problems within a document
-- C. S. Wyatt 2010
--
-- List of Words to Mark as Potential Problems 
set markWords to {"about", "all", "almost", "a lot", "already", "always", "along with", "anxiously", ¬
"absolutely", "as well", "believe", "certainly", "clearly", ¬
"eagerly", "easy", "easily", "every", "feel", "felt", "few", "finally", "frequently", ¬
"good", "got", "intrigued", "intrigues", "just", ¬
"many", "merely", "must", "nearly", "need", "never", "nice", "not", "numerous", ¬
"only", "quick", "quickly", "so", "think", ¬
"utilize", "utilized", "utilizes", "very", ¬
"in the event", "in order to", "on the grounds that", "in case", "the public", ¬
"come to the conclusion"}
tell application "Microsoft Word"
-- Cycle through the markWords and Bold/Underline the words
repeat with theWord in markWords
set findRange to find object of text object of active document
tell findRange
set match whole word to true
set content of replacement of findRange to "{" & theWord & "}"
set bold of font object of replacement of findRange to true
set color index of font object of replacement of findRange to red
set underline of font object of replacement of findRange to underline thick
execute find find text theWord replace replace all
end tell
end repeat

-- Calculate stats
set statWordCount to compute statistics active document statistic statistic words
set statFKGradeLevel to get readability value of readability statistic 10 of text object of active document
set statParagraphs to get readability value of readability statistic 3 of text object of active document
set statSentences to get readability value of readability statistic 4 of text object of active document
set statSentPerParagraph to get readability value of readability statistic 5 of text object of active document
set statWordsPerSent to get readability value of readability statistic 6 of text object of active document
set statPassiveSents to get readability value of readability statistic 8 of text object of active document

-- Move to end of document
set currentDoc to text object of active document
insert break at currentDoc break type section break next page

-- Create a report on the document, after a page break
set currentDoc to collapse range currentDoc direction collapse end
insert paragraph at end of currentDoc
type text selection text "Report on Text"
type paragraph selection
type text selection text "Grade Level: " & statFKGradeLevel
type paragraph selection
type text selection text "Number of Paragraphs: " & statParagraphs & ¬
"; Sentences per Paragraph: " & statSentPerParagraph
type paragraph selection
type text selection text "Number of Sentences: " & statSentences & ¬
"; Words per Sentences: " & statWordsPerSent
type paragraph selection
type text selection text "Passive Sentences: " & statPassiveSents
type paragraph selection
type text selection text "Number of Words: " & statWordCount

end tell

Comments

Popular posts from this blog

MarsEdit and Blogging

MarsEdit (Photo credit: Wikipedia ) Mailing posts to blogs, a practice I adopted in 2005, allows a blogger like me to store copies of draft posts within email. If Blogger , WordPress, or the blogging platform of the moment crashes or for some other reason eats my posts, at least I have the original drafts of most entries. I find having such a nicely organized archive convenient — much easier than remembering to archive posts from Blogger or WordPress to my computer. With this post, I am testing MarsEdit from Red Sweater Software based on recent reviews, including an overview on 9to5Mac . Composing posts an email offers a fast way to prepare draft blogs, but the email does not always work well if you want to include basic formatting, images, and links to online resources. Submitting to Blogger via Apple Mail often produced complex HTML with unnecessary font and paragraph formatting styles. Problems with rich text led me to convert blog entries to plaintext in Apple Mail

Learning to Program

Late last night I installed the update to Apple's OS X programming tool suite, Xcode 4. This summer, in my "free" time I intend to work my way through my old copy of Teach Yourself C and the several Objective-C books I own. While I do play with various languages and tools, from AppleScript to PHP, I've never managed to master Objective-C — which is something I want to do. As I've written several times, knowing simple coding techniques is a practical skill and one that helps learn problem solving strategies. Even my use of AppleScript and Visual Basic for Applications (VBA) on a regular basis helps remind me to tackle problems in distinct steps, with clear objectives from step to step. There are many free programming tools that students should be encouraged to try. On OS X, the first two tools I suggest to non-technical students are Automator and AppleScript. These tools allow you to automate tasks on OS X, similar to the batch files of DOS or the macros of Wor

Learning to Code: Comments Count

I like comments in computer programming source code. I've never been the programmer to claim, "My code doesn't need comments." Maybe it is because I've always worked on so many projects that I need comments  to remind me what I was thinking when I entered the source code into the text editor. Most programmers end up in a similar situation. They look at a function and wonder, "Why did I do it this way?" Tangent : I also like comments in my "human" writing projects. One of the sad consequences of moving to digital media is that we might lose all the little marginalia authors and editors leave on manuscript drafts. That thought, the desire to preserve my notes, is worthy of its own blog post — so watch for a post on writing software and notes. Here are my rules for comments: Source code files should begin with identifying comments and an update log. Functions, subroutines, and blocks of code should have at least one descriptive comment.