Welcome to the forums! There is indeed an easy way to do this using Spice. Spice is an Espresso sugar that makes it very easy to create custom actions coded in Javascript using a growing selection of utility classes (powered by Mootools). As you’ll see in the example code below, there’s no need to understand Objective-C.
First off, install Spice 1.0 beta 6:
http://onecrayon.com/downloads/Spice.zip
After installing Spice, navigate here in the Finder:
~/Library/Application Support/Espresso/
Once there, create a folder called Support. Inside Support create two folders: TextActions and Scripts. Inside TextActions create an XML document called Spice.xml with the following contents:
<action-recipes>
<action id="com.onecrayon.BalanceZone" category="actions.text.generic">
<class>Spice</class>
<title>Balance Syntax Zone</title>
<setup>
<script>balance_zone</script>
<undo_name>Balance Syntax Zone</undo_name>
</setup>
</action>
</action-recipes>
This defines a new custom action for Espresso. Here’s more info about Spice action XML, including info on adding a keyboard shortcut for the action.
After the XML file is created, go into your Espresso Preferences, choose the Advanced tab, and in the TEA for Espresso prefs make sure that “Enable TEA custom user actions” is checked. After that, you’ll need to restart Espresso twice to get the action to show up in the Actions menu. This is due to limitations in how Espresso loads actions from XML.
Before the action will do anything, though, you need to create a new file in the Support/Scripts folder called balance_zone.js with the following contents:
// balance_zone
// Selects the text in the active syntax zone
// require() allows you easy modular access to Spice's helper classes
var textContext = require('text_action_context').textContext;
// We don't directly use the SyntaxZone class, but need to require it to load in some helpful Range methods for accessing zones
require('syntax_zone');
// exports.main is your primary function
// You could do without a function, but you couldn't return false to have Espresso beep
exports.main = function() {
// Voila
textContext.setSelection(textContext.getFirstSelection().getZone().range);
return true;
}
You don’t have to restart Espresso after creating or modifying the Javascript file, because loading the Javascript is handled by Spice which will always execute the most recent saved version of the file.
This is a very basic action that may come in handy for things other than balancing quotation marks. What it does is use Espresso’s syntax API to find select the lowest syntax zone and select it. It’ll have varying degrees of success in languages depending on how they’ve defined their strings. For instance, in HTML the action will only select the string contents, but in Javascript it also selects the string delimiters.
You could make the action more quote-balancing specific by using text parsing logic instead of syntax zones. I leave it to you to experiment with such things if that tickles your fancy. You’ll find fairly extensive documentation for Spice’s utility classes in the Spice docs, and you can always let me know if there’s something missing, buggy, or confusing.