<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>hi, it&#39;s mike</title>
    <link>https://mike.puddingtime.org/tags/editing/</link>
    <description>Recent content on hi, it&#39;s mike</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>mike@puddingtime.org (mike)</managingEditor>
    <webMaster>mike@puddingtime.org (mike)</webMaster>
    <copyright>© 2026, mike</copyright>
    <lastBuildDate>Thu, 02 Jul 2009 02:38:04 +0000</lastBuildDate>
    <atom:link href="https://mike.puddingtime.org/tags/editing/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Updated: TextSoap with appscript</title>
      <link>https://mike.puddingtime.org/posts/2009-07-02-updated-textsoap-with-appscript/</link>
      <pubDate>Thu, 02 Jul 2009 02:38:04 +0000</pubDate><author>mike@puddingtime.org (mike)</author>
      <guid>https://mike.puddingtime.org/posts/2009-07-02-updated-textsoap-with-appscript/</guid>
      
      <description>(There’s an update at the bottom of this entry)
I used to be a faithful user of TextSoap, a Mac app that’s wildly, wildly useful when you’re dealing with content produced by a number of unpleasant tools (like Microsoft Word).
With TextSoap, you get a suite of text filters that do all sorts of stuff …</description>
      <content:encoded><![CDATA[<p>(There&rsquo;s an update at the bottom of this entry)</p>
<p>I used to be a faithful user of <a href="http://www.unmarked.com/textsoap/index.html">TextSoap</a>, a Mac app that&rsquo;s wildly, wildly useful when you&rsquo;re dealing with content produced by a number of unpleasant tools (like Microsoft Word).</p>
<p>With TextSoap, you get a suite of text filters that do all sorts of stuff to text: Straighten smartquotes, convert things like smartquotes to <a href="http://www.w3schools.com/HTML/html_entities.asp">text or numeric HTML entities</a>, increase or decrease the quote level in a mail message, smarten quotes, perform conversions to typographical conventions (like &ldquo;&ndash;&rdquo; to em dash), and on and on.  If TextSoap doesn&rsquo;t have a pre-built filter to perform an operation, you can write your own.  It even supports regular expressions.</p>
<p>You can use TextSoap like a steroidal text editing program, similar to Text Edit or Notepad or whatever, but it also integrates into the Mac as a service and as contextual items, so it&rsquo;s always easy to use without having to launch a different app. It also provides an AppleScript scripting addition.</p>
<p>I got away from using TextSoap while I was carrying around an eeePC and replaced it instead with some very simple Ruby that ran through a hash of typical conversion tasks on STDIN. It was o.k., but it&rsquo;s one of those things where you always turn up a new edge case every few months and that makes it unsatisfactory as a &ldquo;just works&rdquo; solution.</p>
<p>Now I don&rsquo;t have the eeePC, and I&rsquo;ve been through the <a href="http://mph.puddingbowl.org/2009/06/it-is-like-a-cow-in-that-i-cant-use-it-to-get-work-done/">unpleasant ordeal</a> of  seeing what it would be like to be a Windows dude, so I don&rsquo;t mind augmenting plain old Ruby with some appscript now and then.</p>
<p><s>Since you have to use TextSoap as a scripting addition to automate it, the syntax is a little different when using it with rb-appscript:</s> (See the update below)</p>
<pre><code>!/usr/bin/env ruby

require &quot;rubygems&quot;

require &quot;appscript&quot;

require &quot;osax&quot;

include OSAX

ts = OSAX::ScriptingAddition.new(&quot;TextSoapSA&quot;)

text = STDIN.read

puts ts.tsCleanText(text, :with =&gt; &quot;InternetFriendly&quot;)
</code></pre>
<p>You can chain TextSoap filters by adding extra &ldquo;:with =&gt; &lsquo;foo&rsquo;&rdquo; parameters. It processes them first to last when it&rsquo;s filtering the text.</p>
<p>I dropped that into TextMate as a command snippet and tied it to &ldquo;cmd-shift-s&rdquo; (for &ldquo;scrub&rdquo;) and it flattens text out. HTML entities and smartquotes become their flattest ASCII equivalents, so you can think of the &ldquo;InternetFriendly&rdquo; filter in TextSoap like a ginormous endumbening ray.</p>
<p>Which brings me to why I&rsquo;m using the endumbening ray at all when I&rsquo;d prefer to just convert smartquotes and the like to legal HTML entities: The CMS at work has taken to escaping entities when it renders a story, so all my carefully deployed right and left double quotes, em dashes and others render as literal text: rdquo, ldquo, emdash, etc.</p>
<p>It all has something to do with the chaos induced by a WYSIWYG editor in use. I wouldn&rsquo;t know anything about that because it won&rsquo;t run on the Mac version of any browser I&rsquo;ve got: I experience the CMS as a collection of plain text areas and don&rsquo;t consider that a loss.</p>
<p>I&rsquo;d be more crabby about the whole thing, but <a href="http://www.linuxplanet.com/linuxplanet/opinions/3749/1/">I&rsquo;ve been living with stuff like this for the nine years I&rsquo;ve been in Web publishing</a> and it seems I might as well take a cue from the medium I work in: route around the damage. (Quick aside on that link: at least look at <a href="http://www.linuxplanet.com/linuxplanet/opinions/3749/1/screenshot2146/">the screenshot</a> I provided at the time: How did we not claw our eyes out?</p>
<p>One other note: Putting a script like that in TextMate instead of deploying it from the Services menu, as Apple intended for things like TextSoap, is a little awkward. The Services menu, however, is a minor usability nightmare. Since I&rsquo;ve got the &ldquo;Edit in Textmate&rdquo; plugin installed for all my Cocoa apps, and &ldquo;<a href="https://addons.mozilla.org/en-US/firefox/addon/4125">It&rsquo;s All Text</a>&rdquo; installed in Firefox, it&rsquo;s easier to just worth from within TextMate. As a side benefit, all my command snippets are easily exported and used in another text editor, should I ever switch.</p>
<p><strong>Update:</strong> Thanks to Patrick and Mark in the comments, who point out that TextSoap now ships with a scripting agent (textsoapAgent). It&rsquo;s similar to the scripting addition but the syntax is a hair cleaner and you don&rsquo;t have to include appscript&rsquo;s OSAX support. Here&rsquo;s the example above using the scripting agent instead of the scripting addition:</p>
<pre><code>!/usr/bin/env ruby

require &quot;rubygems&quot;

require &quot;appscript&quot;

ts = app(&quot;textsoapAgent&quot;)

text = STDIN.read

puts ts.cleanText(text, :with =&gt; &quot;InternetFriendly&quot;)
</code></pre>
<p>If you&rsquo;re not sure which cleaners are available or what to call them, the agent includes a few methods to make figuring that out easier:</p>
<p>app(&ldquo;textsoapAgent&rdquo;).groupNames will return the cleaner groups.  In my case:</p>
<p>[&ldquo;Library&rdquo;, &ldquo;:Standard&rdquo;, &ldquo;:Email&rdquo;, &ldquo;:Typographical&rdquo;, &ldquo;:Case Conversions&rdquo;, &ldquo;:Text Quoting&rdquo;, &ldquo;:Markdown&rdquo;, &ldquo;:HTML&rdquo;, &ldquo;:Plist&rdquo;, &ldquo;:Custom&rdquo;, &ldquo;MyList&rdquo;, &ldquo;Mail&rdquo;, &ldquo;BBEdit&rdquo;, &ldquo;Jupitermedia&rdquo;]</p>
<p>and</p>
<p>app(&ldquo;textsoapAgent).groupItems(:from =&gt; &ldquo;<strong>group name</strong>&rdquo;) will return the cleaners with a particular group.  In this instance, &ldquo;MyList,&rdquo;  which is a user-defined selection of filters:</p>
<p>[&ldquo;Markdown Text&rdquo;, &ldquo;InternetFriendly&rdquo;, &ldquo;Remove Forwarding (&gt;) Characters&rdquo;, &ldquo;Convert pseudo-heads&rdquo;, &ldquo;Capitalize Title&rdquo;, &ldquo;double to single quotes&rdquo;, &ldquo;Remove All Tabs&rdquo;, &ldquo;Remove Extra Spaces&rdquo;, &ldquo;Remove Extra Returns&rdquo;, &ldquo;Blog Preparation&rdquo;, &ldquo;Markdown&rdquo;, &ldquo;Remove Extra Spaces&rdquo;]</p>
<p>#editing #mac #ruby #text #textsoap</p>
<p><em><a href="mailto:mike@puddingtime.org?subject=Re%3A%20Updated%3A%20TextSoap%20with%20appscript">Drop a line about this</a>.</em></p>]]></content:encoded>
    </item>
  </channel>
</rss>
