<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Scripting for Lawyers</title>
	
	<link>http://scriptingforlawyers.com</link>
	<description>Boss Around Your Apps</description>
	<pubDate>Mon, 22 Sep 2008 14:28:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<geo:lat>35.409544</geo:lat><geo:long>-80.863622</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/ScriptingForLawyers" type="application/rss+xml" /><feedburner:emailServiceId>ScriptingForLawyers</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Scripting Documents with LaTeX</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/Bh55gX6wCq4/</link>
		<comments>http://scriptingforlawyers.com/2008/09/22/scripting-documents-with-latex/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 14:28:05 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[AppleScript]]></category>

		<category><![CDATA[FileMaker]]></category>

		<category><![CDATA[Finder]]></category>

		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=60</guid>
		<description><![CDATA[Before you can create documents with LaTeX, you must install a TeX distribution. A TeX distribution is the underlying software that typesets your documents for you and outputs the PDF document. The easiest way to install a distribution is to download and install the MacTeX TeXLive 2008 distribution. This distribution installs just about everything you [...]]]></description>
			<content:encoded><![CDATA[<p>Before you can create documents with LaTeX, you must install a TeX distribution. A TeX distribution is the underlying software that typesets your documents for you and outputs the PDF document. The easiest way to install a distribution is to download and install the <a href="http://tug.org/mactex/">MacTeX TeXLive 2008 distribution</a>. This distribution installs just about everything you will need to begin drafting documents. And, yes, the distribution is free.</p>
<p>Because LaTeX/XeTeX files are simply plain text, you can draft your documents in any text editor. However, for beginners, I recommend <a href="http://www.uoregon.edu/~koch/texshop/">TeXShop</a>. With TeXShop, you can draft and compile your document in one application. I use TextMate to draft and compile my documents, but it requires some setup. You can use TeXShop immediately after downloading it and installing it in your /Applications folder.</p>
<p>After installing TeXLive 2008 and TeXShop, you can begin to draft documents. Let&#8217;s start with an easy one. Open TeXShop and type the following:<br />
<code><br />
\documentclass{article}</p>
<p>\begin{document}<br />
Hello, world. This is the first paragraph.</p>
<p>This is the second paragraph.<br />
\end{document}<br />
</code></p>
<p>LaTeX/XeTeX documents always begin with a \documentclass command. In almost every case, you will use the article document class.</p>
<p>Next, you send the \begin{document} command to LaTeX to let it know where your document begins. You then write your text. When you are done, you send the \end{document} command to LaTeX. In TeXShop, press the &#8220;Typeset&#8221; button and you should see the output. Notice that LaTeX automatically set the margins and added the page number at the bottom of the page. Of course, we can customize all the properties of your document if needed.</p>
<p>So, how can we fit this into our workflow? Suppose that you want to draft a letter to a contact from your FileMaker database. First, you would have to get the data from your database. Your script might look something like this:<br />
<code><br />
tell application "FileMaker Pro"<br />
    tell database "Contacts.fp7"<br />
        set addressee to "fullName" of current record<br />
    end tell<br />
end tell<br />
</code></p>
<p>Now, you can construct a string of text to use as your document:<br />
<code><br />
set latexString to "\\documentclass{article}" &#038; return &#038; "\\begin{document}" &#038; return &#038; "Hello, " &#038; addressee &#038; " This is the first paragraph." &#038; return &#038; return &#038; "This is the second paragraph." &#038; return &#038; "\\end{document}"<br />
</code></p>
<p>This string looks just like our LaTeX document that we typeset above, except that we need to escape the backward slashes so we don&#8217;t confuse AppleScript.</p>
<p>Next, we need to write the string out to a file. This serves two purposes. First, we cannot compile our documents easily without a document file. Second, we have a document to put under version control. To write a string out to a file, type the following:<br />
<code><br />
try<br />
	set filePath to (((path to desktop) as string) &#038; "letter.tex")<br />
	set f to open for access file filePath with write permission<br />
	write latexString to f<br />
	close access f<br />
on error e<br />
	close access f<br />
end try<br />
</code></p>
<p>This code sets a path to a file on our desktop. If the file doesn&#8217;t already exists (and it shouldn&#8217;t), then AppleScript creates a blank file for us. We then write our latexString to the file and close the file. Notice the error handling, too. We use this to ensure that our file gets closed. AppleScript does not like it when you open a file and forget to close it.</p>
<p>In the Finder, you should see a new document on your desktop named &#8220;letter.tex&#8221;. To typeset the document, we will use TeXShop&#8217;s AppleScript dictionary. Type this into your script:<br />
<code><br />
tell application "TeXShop"<br />
	set doc to open file filePath<br />
	typeset doc<br />
end tell<br />
</code></p>
<p>This chunk of code tells TeXShop to open the document and typeset it. Easy. When you run the script, you should see a file named &#8220;letter.pdf&#8221; on your desktop. Open it up and you will see your document typeset in PDF. But what are all those extra documents on the desktop? Relax. TeX outputs a log file and an auxillary file every time it compiles your document. The log file contains any errors or warning messages. You can safely delete these files.</p>
<p>As with many scripts, this seems like a lot of work. But the beauty of scripting is that you only need to setup your scripts once and then run them over and over again.</p>
<p>In the next installment, we&#8217;ll look at how to use your Mac fonts with TeX using XeTeX.<br />
<span id="more-60"></span><br />
I note that you don&#8217;t need to use TeXShop to typeset your documents. You can use the &#8220;do shell script&#8221; command to typeset your documents using programs from the command line. This requires some advanced setup that is beyond the scope of this tutorial.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=Bh55gX6wCq4:og3xXCmpyf8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=Bh55gX6wCq4:og3xXCmpyf8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=Bh55gX6wCq4:og3xXCmpyf8:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/Bh55gX6wCq4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/09/22/scripting-documents-with-latex/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/09/22/scripting-documents-with-latex/</feedburner:origLink></item>
		<item>
		<title>Scripting Beautiful Documents in Plain Text</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/nyUC0CSmOTw/</link>
		<comments>http://scriptingforlawyers.com/2008/08/22/scripting-beautiful-documents-in-plain-text/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 01:14:07 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=50</guid>
		<description><![CDATA[A common complaint among lawyers and other users of word processor applications is that word processors get in the way of the user writing their text. Envision a legal professional drafting a brief. The professional will type the court caption, select the caption, and select &#8220;Center&#8221; from the &#8220;Alignment&#8221; palette. This workflow of writing, then [...]]]></description>
			<content:encoded><![CDATA[<p>A common complaint among lawyers and other users of word processor applications is that word processors get in the way of the user writing their text. Envision a legal professional drafting a brief. The professional will type the court caption, select the caption, and select &#8220;Center&#8221; from the &#8220;Alignment&#8221; palette. This workflow of writing, then formatting continues until the end of the document with the legal professional hoping that a change to the formatting of one section of the brief doesn&#8217;t mysteriously change another section. Auto-numbering of paragraphs, anyone? Other legal professionals type out their text, then hand it off to a colleague for formatting. Both workflows are cumbersome and both workflows duplicate work.</p>
<p>So what&#8217;s the solution? Before getting to that, let&#8217;s think about some requirements that we expect from a document production system. First, we want to focus on writing, not formatting. Second, we want the output to look great. No more mixing of fonts or strange leading. Third, we want to be able to incorporate our system into our overall workflow via scripting. We might also want the format to be portable, capable of versioning, and obsolescence-proof.</p>
<p>With these requirements, the choice for the format looks clear:  plain text. Plain text allows you to focus on writing. Just open your text editor and start typing. But what about formatting? We can mark up our plain text to format our document. HTML is an example of marked up plain text. Plain text can also produce great looking output through a typesetting system called <a href="http://www.tug.org">LaTeX</a>. LaTeX files are marked up plain text files that, when typeset, look fantastic. Here&#8217;s an example of a document typeset in LaTeX: <a href='http://scriptingforlawyers.com/wp-content/uploads/2008/08/answer.pdf'>Answer Typeset in LaTeX</a>. As you can see, LaTeX produces beautiful documents with consistent margins, consistent paragraph numbering, and output as PDF. I encourage you to download the PDF file above and zoom in to reveal the details.</p>
<p>Of course, plain text documents will easily incorporate into any scripted workflow. Indeed, your scripts will generally run faster with plain text documents because you will not incur the overhead of opening another application to format your text. In addition, you can take plain text documents to any computer and open them for editing. You can even install LaTeX on just about any operating system. Plain text documents are also capable of versioning, also known as &#8220;track changes&#8221; in Word. You can do simple versioning using the <code>diff</code> tool or more sophisticated versioning using software such as <a href="http://subversion.tigris.org/">Subversion</a> or <a href="http://git.or.cz/">Git</a>. With Subversion and Git, you can upload your documents to a private server (&#8221;repository&#8221;) and allow others to view and edit the text. You then update your personal repository on your local computer and the changes appear. Don&#8217;t like the changes? Roll back to the last version. I have all of my LaTeX files in a Subversion repository. Note, too, that the offsite repository acts as a backup file system.</p>
<p>Finally, plain text is nearly obsolescence-proof. Unless a new way of computing appears soon and does away with plain text, then your documents are safe from becoming as useless as WordPerfect files on the Mac. (Yes, I know about WP3.5 and SheepShaver.)</p>
<p>So how can we incorporate these plain text documents into our workflows? I&#8217;ll show you in the next installment. Stay tuned!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=nyUC0CSmOTw:-XEtzfzARfk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=nyUC0CSmOTw:-XEtzfzARfk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=nyUC0CSmOTw:-XEtzfzARfk:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/nyUC0CSmOTw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/08/22/scripting-beautiful-documents-in-plain-text/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/08/22/scripting-beautiful-documents-in-plain-text/</feedburner:origLink></item>
		<item>
		<title>Scripting Pages</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/tJI9fI-mMcc/</link>
		<comments>http://scriptingforlawyers.com/2008/08/20/scripting-pages/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 12:57:08 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[AppleScript]]></category>

		<category><![CDATA[Pages]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=49</guid>
		<description><![CDATA[So far, we&#8217;ve dumped the output from our scripts into Microsoft Word. In this post, we&#8217;ll briefly look at Apple&#8217;s Pages application, which comes bundled with its iWork &#8216;08 suite. Apple really improved their AppleScript support in this latest iteration of Pages.
When you want to manipulate a Pages document, you should get the document class [...]]]></description>
			<content:encoded><![CDATA[<p>So far, we&#8217;ve dumped the output from our scripts into Microsoft Word. In this post, we&#8217;ll briefly look at Apple&#8217;s Pages application, which comes bundled with its iWork &#8216;08 suite. Apple really improved their AppleScript support in this latest iteration of Pages.</p>
<p>When you want to manipulate a Pages document, you should get the <code>document</code> class of your document:</p>
<p><code>set doc to document 1</code></p>
<p>You can now tell doc to change the properties and elements of your document. One of the main properties of the document class is <code>body text</code>. Body text is the main flow of your text document. If you extract data from your database and copy that data to the clipboard, you use AppleScript to paste that data to the body text of your Pages document.</p>
<p><code>set body text of doc to the clipboard</code></p>
<p>A Pages document is also comprised of <code>pages</code>, <code>sections</code>, and <code>paragraphs</code>, which you can access through AppleScript.</p>
<p>Because Pages also acts as a page layout application, you can create and access <code>text boxes</code>, <code>shapes</code>, <code>graphics</code>, and <code>images</code>.</p>
<p>We&#8217;ll look at Pages more as we go forward, but you should know that Pages has an excellent AppleScript dictionary and can be used in your workflows.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=tJI9fI-mMcc:-H0NNU7z3IY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=tJI9fI-mMcc:-H0NNU7z3IY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=tJI9fI-mMcc:-H0NNU7z3IY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/tJI9fI-mMcc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/08/20/scripting-pages/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/08/20/scripting-pages/</feedburner:origLink></item>
		<item>
		<title>At Your Service</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/HtuqAH5-wkI/</link>
		<comments>http://scriptingforlawyers.com/2008/07/08/at-your-service/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 18:53:35 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[Administrative]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=47</guid>
		<description><![CDATA[Just a friendly reminder that I am available for hire. From simple scripts to automate common tasks to scripting complex workflows, I can help you improve your productivity and bottom line. 
I&#8217;m also available to develop and design database solutions for your business. I have extensive experience with FileMaker Pro and open source databases such [...]]]></description>
			<content:encoded><![CDATA[<p>Just a friendly reminder that I am available for hire. From simple scripts to automate common tasks to scripting complex workflows, I can help you improve your productivity and bottom line. </p>
<p>I&#8217;m also available to develop and design database solutions for your business. I have extensive experience with FileMaker Pro and open source databases such as MySQL, PostgreSQL, and SQLite.</p>
<p>You can contact me at <a href="mailto:info@sweetpeasoftware.com">info@sweetpeasoftware.com</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=HtuqAH5-wkI:Z0ZK3KwLMKo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=HtuqAH5-wkI:Z0ZK3KwLMKo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=HtuqAH5-wkI:Z0ZK3KwLMKo:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/HtuqAH5-wkI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/07/08/at-your-service/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/07/08/at-your-service/</feedburner:origLink></item>
		<item>
		<title>Help Request: Table of Authorities</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/ln6a2gwO3Rg/</link>
		<comments>http://scriptingforlawyers.com/2008/07/07/help-request-table-of-authorities/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 19:06:22 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[AppleScript]]></category>

		<category><![CDATA[Pages]]></category>

		<category><![CDATA[Screencast]]></category>

		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=48</guid>
		<description><![CDATA[Dear readers, I&#8217;m writing a script that generates a Table of Authorities from a Pages document and I need your help. I&#8217;ve determined 2 ways to delimit a citation for inclusion in the Table and I&#8217;m interested in your thoughts on how to implement this all-important feature. 
First, the user could highlight the citation, then [...]]]></description>
			<content:encoded><![CDATA[<p>Dear readers, I&#8217;m writing a script that generates a Table of Authorities from a Pages document and I need your help. I&#8217;ve determined 2 ways to delimit a citation for inclusion in the Table and I&#8217;m interested in your thoughts on how to implement this all-important feature. </p>
<p>First, the user could highlight the citation, then select the type of citation (case or statute) from a dialog box. Microsoft Word for Windows uses this method. I don&#8217;t particularly like this method, but it&#8217;s familiar to many switchers. </p>
<p>The second way is to delimit the citations using a markup language. For example, one might use something like \case{A v. B., 123 U.S. 456 (2008)} within their text to delimit the case citation. With my background in LaTeX and HTML, I prefer this method as it&#8217;s easier to parse the document. Moreover, the user would not have to go back and highlight each citation, hoping not to miss a citation. Instead, the user would simply delimit the cases as he or she types. </p>
<p>Here&#8217;s a <a href="http://larrystaton.com/media/toa.mov">quick movie</a> of what I have so far. I&#8217;d love to get your feedback on how you might delimit the citations. Thanks!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=ln6a2gwO3Rg:uu42_x7bEc0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=ln6a2gwO3Rg:uu42_x7bEc0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=ln6a2gwO3Rg:uu42_x7bEc0:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/ln6a2gwO3Rg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/07/07/help-request-table-of-authorities/feed/</wfw:commentRss>
<enclosure url="http://larrystaton.com/media/toa.mov" length="2175295" type="video/quicktime" />
		<feedburner:origLink>http://scriptingforlawyers.com/2008/07/07/help-request-table-of-authorities/</feedburner:origLink></item>
		<item>
		<title>Search-And-Replace Templates</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/bjoSYzDUhWw/</link>
		<comments>http://scriptingforlawyers.com/2008/07/01/search-and-replace-templates/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 20:13:34 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[AppleScript]]></category>

		<category><![CDATA[Word]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=46</guid>
		<description><![CDATA[In our last post, we looked at script-based templates, which are those templates that are stored within the script. In this post, we&#8217;ll look at search-and-replace templates. With these templates, our script searches a template with preset tags and replaces those tags with our data. As with the last example, we&#8217;ll use Microsoft Word as [...]]]></description>
			<content:encoded><![CDATA[<p>In our <a title="Script-based templates" href="http://scriptingforlawyers.com/2008/06/17/script-based-templates/">last post</a>, we looked at script-based templates, which are those templates that are stored within the script. In this post, we&#8217;ll look at search-and-replace templates. With these templates, our script searches a template with preset tags and replaces those tags with our data. As with the last example, we&#8217;ll use Microsoft Word as our word processor. We&#8217;ll look at LaTeX and Pages in later posts.</p>
<p>Before we get to our script, we need to create a template with preset tags. Open up Microsoft Word and type the following:<br />
<code><br />
Dear First_Name:</code><br />
<code>Please call me at Appt_Time on Appt_Date to discuss your case.<br />
</code><br />
Save your document to your desktop as &#8220;template.doc&#8221;. As you can see, this template includes 3 tags:  First_Name, Appt_Time, and Appt_Date. Our script will search for these tags and replace the tags with data from our data source.</p>
<p>Let&#8217;s again suppose that we retrieved the relevant data from our data source and stored the data in 3 variables:<br />
<code><br />
set firstName to "Larry"<br />
set appointmentDate to "July 4, 2008"<br />
set appointmentTime to "9:00"<br />
</code><br />
Now that we have our data, we need to open up our template document, search for each tag, replace the tag with the variable data, and then save the document as a different name. Here goes:<br />
<code><br />
tell application "Microsoft Word"<br />
        set doc to open ((path to desktop as string) &#038; "template.doc")<br />
        set findRange to find object of selection<br />
        tell findRange<br />
                execute find find text "First_Name" replace with firstName replace replace all<br />
                execute find find text "Appt_Time" replace with appointmentTime replace replace all<br />
                execute find find text "Appt_Date" replace with appointmentDate replace replace all<br />
        end tell<br />
        save as active document file name "letter.doc"<br />
end tell<br />
</code><br />
What&#8217;s going on here? In the second line, we open the template file using a special command called &#8220;path to desktop&#8221;. This command returns the path to the desktop as an alias, which we convert to a string and concatenate our template file name. The document is now open. In the third line we create a find object for our document. This find object is specific to Microsoft Word. The find object specifies a range of text to execute our search and replace. Because nothing is selected, Word assigns the entire document to the find object. In lines 4–8, we tell our find object to execute a find by finding text and replacing the text with the data stored in our variables. At the end of lines 5–7, we need to tell the find object to &#8220;replace all&#8221; occurrences of the found text. In line 9, we save the document as &#8220;letter.doc&#8221; to preserve our template.</p>
<p>Using this method, you only have to prepare the script once and the script will run properly. If you want to change the template, you do not need to change the script (unless you want to add variables). This type of template scripting (mostly) separates your logic from your presentation and is generally easier to maintain.</p>
<p>In the next lesson, we&#8217;ll look at search and replace using a third-party OSAX.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=bjoSYzDUhWw:JG2qHtOJxO8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=bjoSYzDUhWw:JG2qHtOJxO8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=bjoSYzDUhWw:JG2qHtOJxO8:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/bjoSYzDUhWw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/07/01/search-and-replace-templates/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/07/01/search-and-replace-templates/</feedburner:origLink></item>
		<item>
		<title>Script-Based Templates</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/UKEnXnt1pRc/</link>
		<comments>http://scriptingforlawyers.com/2008/06/17/script-based-templates/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 03:18:28 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[AppleScript]]></category>

		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=45</guid>
		<description><![CDATA[In our last post, we discussed using templates and how you can integrate a template with a data source such as a database to create documents. We also discussed two ways to solve this problem. The first solution involves using writing the template into your script while the second solution involves searching and replacing for [...]]]></description>
			<content:encoded><![CDATA[<p>In our last post, we discussed using templates and how you can integrate a template with a data source such as a database to create documents. We also discussed two ways to solve this problem. The first solution involves using writing the template into your script while the second solution involves searching and replacing for key words in a document. This post explores the first solution.</p>
<p>When writing a script that incorporates your template, you should be aware of a few things. First, you need to remember that if your template changes, then you need to change your script. This can be trivial, but it can also lead to some problems if you aren&#8217;t careful. Second, you need to be aware of any <em>escape characters</em> in your script. Escape characters are used when you want AppleScript to ignore its normal behavior when dealing with certain characters and, instead, behave according to different rules. For example, if we want to set a variable named <code>sampleText</code> to a text string, we would do this:</p>
<p><code>set sampleText to "This is a text string."</code></p>
<p>But what if we wanted to use a literal quote in our text string? The immediate response is to simply add the quotation marks like so:</p>
<p><code>set sampleText to "This is a "quoted" text string."</code></p>
<p>AppleScript will raise an error for this code because it will come to the second quotation mark (the one before the letter &#8220;q&#8221; in &#8220;quoted&#8221;) and interpret that mark as the closing quote for the first quotation mark. So what do we do? We <em>escape</em> the quotation mark using the forward slash escape character, &#8220;\&#8221;.</p>
<p><code>set sampleText to "This is a \"quoted\" text string."</code></p>
<p>So if your template contains lots of quotation marks, you&#8217;ll have to be careful of those escape characters.</p>
<p>Back to our script. Another issue to consider involves what to do with the output of your script. Unlike the second type of script where we will search-and-replace from within a Word document, in this script, we will create the entire template in our script. The next step involves moving the template output from the script to your word processor. A simple way to do this involves copying the final template output to the clipboard, then pressing Command+V in the word processor of your choice.</p>
<p>Let&#8217;s look at a simple template. Suppose that we want to write a brief letter to a client with the following template:</p>
<p><code><br />
Dear FIRST_NAME:</code></p>
<p><code>Please call me on APPOINTMENT_DATE at APPOINTMENT_TIME to discuss your case.</p>
<p>Sincerely,</p>
<p></code></p>
<p><code>Me<br />
</code></p>
<p>Let&#8217;s further suppose that we have a FileMaker database that holds the data for this client&#8217;s FIRST_NAME, APPOINTMENT_DATE, and APPOINTMENT_TIME. Because we do not have a FileMaker database setup for this, we&#8217;ll just assume that we&#8217;ve taken the data out of FileMaker and we have stored it in some variables:</p>
<p><code><br />
set firstName to "Larry"<br />
set appointmentDate to "June 18, 2008"<br />
set appointmentTime to "9:00"<br />
</code></p>
<p>Before going further, note the use of descriptive variable names. While not required, I recommend using descriptive variable names to help you keep track of your variables. Imagine if you named each variable x, y, and z. After several uses of each, you would quickly get confused.</p>
<p>On to the template. Now that we have our variables, we can simple plug them into the template. Type the following into Script Editor and run it:</p>
<p><code><br />
set firstName to "Larry"<br />
set appointmentDate to "June 18, 2008"<br />
set appointmentTime to "9:00"</code></p>
<p><code>set templateOutput to "Dear " &amp; firstName &amp; ":" &amp; return &amp; return &amp; "Please call me on " &amp; appointmentDate &amp; " at " &amp; appointmentTime &amp; " to discuss your case." &amp; return &amp; return &amp; "Sincerely," &amp; return &amp; return &amp; "Me"</p>
<p></code></p>
<p> </p>
<p>The first three lines are the variables from above. The next variable, <code>templateOutput</code>, holds our final template. We begin with the first line with &#8220;Dear &#8220;. Note the space after &#8220;Dear &#8220;. We need this because our variable does not know about spaces before or after itself and a variable follows &#8220;Dear &#8220;. Next we see the ampersand character. The ampersand character tells AppleScript to concatenate the text on either side of the ampersand. Here, we concatenate &#8220;Dear &#8221; and our <code>firstName</code> variable. We then concatenate a colon on to the end of the first line. Next, we concatenate a <code>return</code>. <code>return</code> is a reserved word in AppleScript that does just what you think it does&amp;emdash;it inserts a return at the end of a line. In our case, we concatenate another return to effect two lines. The rest of the script follows these same principles.</p>
<p>Now that we have our output, we need to copy it to the clipboard. Add this line to your script:</p>
<p><code>set the clipboard to templateOutput</code></p>
<p>Compile and run your script. You should not see any output in the &#8220;Result&#8221; tab in the bottom pane of Script Editor. Now open TextEdit and press Command+V to paste your output into TextEdit. Now open up Word, Pages, NeoOffice, or your favorite word processor and paste your output into the frontmost document. Because we&#8217;ve copied the output to the clipboard, we can paste that output anywhere we can use the clipboard.</p>
<p>Well, you&#8217;ve done it! You created a simple template and inserted variables into the template for insertion into a document. Next, we&#8217;ll look at using search-and-replace to insert those variables into a document.<br />
 </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=UKEnXnt1pRc:G5JA6JNkSpM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=UKEnXnt1pRc:G5JA6JNkSpM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=UKEnXnt1pRc:G5JA6JNkSpM:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/UKEnXnt1pRc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/06/17/script-based-templates/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/06/17/script-based-templates/</feedburner:origLink></item>
		<item>
		<title>Contemplating Templating</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/gPImnDaN2iQ/</link>
		<comments>http://scriptingforlawyers.com/2008/06/09/contemplating-templating/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 13:34:10 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[AppleScript]]></category>

		<category><![CDATA[Database]]></category>

		<category><![CDATA[Text]]></category>

		<category><![CDATA[Word]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=44</guid>
		<description><![CDATA[In many professions, knowledge workers use forms with special fields to be filled in—templates, in other words—to speed along their daily tasks. Legal professionals are no exception. We use templates to efficiently create documents for our clients. Bankruptcy petitions, trademark applications, copyright applications, and real estate closing documents are just a few examples of templates [...]]]></description>
			<content:encoded><![CDATA[<p>In many professions, knowledge workers use forms with special fields to be filled in—templates, in other words—to speed along their daily tasks. Legal professionals are no exception. We use templates to efficiently create documents for our clients. Bankruptcy petitions, trademark applications, copyright applications, and real estate closing documents are just a few examples of templates used by legal professionals. AppleScript can help improve the efficiency in creating and tracking these documents.</p>
<p>A typical template includes pre-defined fields where data from a database or spreadsheet gets inserted. For example, we might have the following greeting in a template:</p>
<p><code>Dear FIRST_NAME LAST_NAME:</code></p>
<p>With this template, we would replace the <code>FIRST_NAME</code> field in the template with data from our data source. We would then do the same for the <code>LAST_NAME</code> field. At a basic level, this resembles a merge that you might find as a feature in Word or WordPerfect. But we can use AppleScript to control all aspects of this &#8220;merge&#8221; including calculating values and making decisions depending on the values in your data source. In addition, by using AppleScript, you are not necessarily tied to one word processing vendor.</p>
<p>There are two ways to accomplish this task. With the first method, we can recreate the entire document from scratch every time we run our script. Our script will hold the template, use variables to replace the fields in the template, then write out the entire document to a file. The second method uses search and replace to find the template variables and change them to the proper variables.</p>
<p>The advantage of the first method is that the final script need not be dependent on your word processor. You can simply copy the resulting template to the clipboard and the paste it into your preferred word processor. The advantage of the second method is that you can use existing templates to the extent that they exist. In addition, if you want to change the template, you don&#8217;t have to fiddle with your script.</p>
<p>In the next two posts, we&#8217;ll look at each method of using templates to create documents.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=gPImnDaN2iQ:xSANLlxSuJA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=gPImnDaN2iQ:xSANLlxSuJA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=gPImnDaN2iQ:xSANLlxSuJA:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/gPImnDaN2iQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/06/09/contemplating-templating/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/06/09/contemplating-templating/</feedburner:origLink></item>
		<item>
		<title>Fun with…Rocket Matter?</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/w-IyO92d1Qk/</link>
		<comments>http://scriptingforlawyers.com/2008/06/03/fun-with%e2%80%a6rocket-matter/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 01:00:16 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[AppleScript]]></category>

		<category><![CDATA[Screencast]]></category>

		<category><![CDATA[Word]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=42</guid>
		<description><![CDATA[Rocket Matter is a Web-based case management system for lawyers and law firms. When I first heard about Rocket Matter, I immediately inquired about an API (Application Programming Interface) for accessing one&#8217;s data via AppleScript (or any other programming language). I told the developers at Rocket Matter that I wanted to access my data from [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Web-based case management system" href="http://www.rocketmatter.com">Rocket Matter</a> is a Web-based case management system for lawyers and law firms. When I first heard about Rocket Matter, I immediately inquired about an API (Application Programming Interface) for accessing one&#8217;s data via AppleScript (or any other programming language). I told the developers at Rocket Matter that I wanted to access my data from Rocket Matter&#8217;s secure databases and push that data to various applications on my Mac. The developers graciously granted my request and we&#8217;ve been working on an API to allow such access. Although the API is still experimental, I was able to produce this video to show you that Web applications need not be a burden to your scripting. Enjoy.</p>
<p>UPDATE: You may need to turn up your volume. I need to get a microphone for these screencasts.</p>
<p><a href="http://scriptingforlawyers.com/wp-content/uploads/2008/06/rocketmatter.mov">Scripting Rocket Matter</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=w-IyO92d1Qk:Gk5aRpucr20:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=w-IyO92d1Qk:Gk5aRpucr20:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=w-IyO92d1Qk:Gk5aRpucr20:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/w-IyO92d1Qk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/06/03/fun-with%e2%80%a6rocket-matter/feed/</wfw:commentRss>
<enclosure url="http://scriptingforlawyers.com/wp-content/uploads/2008/06/rocketmatter.mov" length="5617231" type="video/quicktime" />
		<feedburner:origLink>http://scriptingforlawyers.com/2008/06/03/fun-with%e2%80%a6rocket-matter/</feedburner:origLink></item>
		<item>
		<title>FileMaker to Word</title>
		<link>http://feedproxy.google.com/~r/ScriptingForLawyers/~3/iesk-EazMj0/</link>
		<comments>http://scriptingforlawyers.com/2008/05/28/filemaker-to-word/#comments</comments>
		<pubDate>Wed, 28 May 2008 17:34:07 +0000</pubDate>
		<dc:creator>statonjr</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scriptingforlawyers.com/?p=41</guid>
		<description><![CDATA[Despite all the trash talk around Vista and Windows, Microsoft&#8217;s Mac Business Unit makes some of the best software for the Mac. While I prefer writing my documents in XeTeX, I often use Microsoft Word in my scripting solutions. The MacBU implemented a terrific AppleScript dictionary for Word (and the other Office apps as well) [...]]]></description>
			<content:encoded><![CDATA[<p>Despite all the trash talk around Vista and Windows, Microsoft&#8217;s Mac Business Unit makes some of the best software for the Mac. While I prefer writing my documents in <a href="http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&amp;id=xetex">XeTeX</a>, I often use Microsoft Word in my scripting solutions. The MacBU implemented a terrific AppleScript dictionary for Word (and the other Office apps as well) such that Word interfaces perfectly with FileMaker and other scriptable applications.</p>
<p>So let&#8217;s look at how we might get our data from FileMaker to Word. In our last script, we told FileMaker to get the first name and last name of the first record of our Contact Management database. In the last line of our script, we stuffed that data into a variable named <em>fullName</em>. Let&#8217;s put <em>fullName</em> into Word as we might do if we wanted to draft a letter to this person.</p>
<pre>tell application "Microsoft Word"
	tell selection
		type text text fullName
	end tell
end tell</pre>
<p>There are several different ways to insert text into a Microsoft Word document. With Word&#8217;s robust AppleScript dictionary, you can even access Word&#8217;s AutoText feature to insert text. In this example, we use the simplest way to insert text—we tell Word to <em>type text</em>. In line 2, notice that we don&#8217;t tell document 1 to do anything. In Word, you can work with selection objects and text range objects to insert your text precisely where you need it. Don&#8217;t worry about what is a selection object or text range object right now. Just know that when you <em>tell selection</em>, you insert text at the insertion point (i.e., the blinking cursor). On a blank document, the insertion point will be at the beginning of the document.</p>
<p>In our last few posts, we&#8217;ve seen how to use AppleScript to access data from a database and push it to a word processor. You can do this on your local machine. You could also access a remote database and push it to the word processor on your MacBook. Hopefully, you&#8217;re beginning to imagine the possibilities of what you can do with AppleScript. One possibility is using AppleScript to push data from FileMaker to Word templates. We&#8217;ll look at that idea in our next installment.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=iesk-EazMj0:ZTsjWcFoZB0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ScriptingForLawyers?a=iesk-EazMj0:ZTsjWcFoZB0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ScriptingForLawyers?i=iesk-EazMj0:ZTsjWcFoZB0:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ScriptingForLawyers/~4/iesk-EazMj0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://scriptingforlawyers.com/2008/05/28/filemaker-to-word/feed/</wfw:commentRss>
		<feedburner:origLink>http://scriptingforlawyers.com/2008/05/28/filemaker-to-word/</feedburner:origLink></item>
	</channel>
</rss>
