So I fielded an interesting question a few weeks ago and it turned into an Automator
script, a really simple Automator script, and I thought it was very useful.
The idea is to enclose selected text into some sort of characters like, for instance,
quotes.
So I could select, say, this sentence here and say I wanted to enclose it in quotes.
Well I could go and add, of course, a quote here and a quote there and do it that way.
But what if this is a task that you do pretty often.
I would love to be able to select text and then hit a shortcut and quotes go around it.
So how would you do this?
Well, you can do it in Automator.
So let's launch Automator and let's create a new script.
So I'm going to go New and I'm going to do a Quick Action.
This will allow me to add something to the Services Menu of Applications.
So I'll Choose that and I get some options up here.
I could say I want it to receive something Automatic or in this case I'm going to say
I want it to receive Rich Text because this is really only going to be something that
I only use in text.
I'm going to use it in Pages for instance.
In Any Application so that way in Pages but also in other apps that I use for text editing.
Then I'll just stick with the default Image and Color.
The only thing I need to put in here is a JavaScript piece of code.
Now JavaScript, when I add the Run JavaScript automator action, it gives me a function which
accepts input.
The input is going to be what comes in from the action.
So in this case it's going to be the text.
All I need to do is manipulate that text.
This is so easy to do in JavaScript.
So I'm going to do input equals and then I'm going to put quotes.
Then I'm going to create the quotes.
I'm going to do Option and then the left bracket for the curly quote on the one side.
Put that in quote.
Plus the original input plus and in quotes Shift and Option and the left bracket to get
the other side of the curly quotes.
So that changes the input to be the input plus a quote on either side.
Then it's going to return it.
Now there's a checkbox up here that says Output replaces selected text.
That exactly what we want.
Great.
So I'll select that and it looks like we're ready to go.
Do Command S for save and I'll save it as Enclose in Quotes.
There we go.
So I can now quit Automator and go back to Pages.
Now in Pages, if I go to Pages, Services this is where I will find it.
But before I actually even use it I'm going to go to Services, Preferences.
This will take me to System Preferences.
Here I can close most of the options here and look for Text.
Sure enough there is Enclose in Quotes.
This is where I get to add a keyboard shortcut.
So I'm going to Command and then the just the single quote, which is also the double
quote there, so that's a really easy one to do as a shortcut.
I don't think it's being used for much else.
That should take care of it.
So now when I look under Services and look for Enclose in Quotes I'll see that that's
the shortcut.
I could just use the menu item here but instead I'll use the keyboard shortcut.
I'll do that and you can see it encloses that in quotes.
So I can select anything I want and enclose it in quotes.
You can use this for a variety of different things.
So, for instance, I could instead of using quotes I could have use parentheses.
Or something that's a little harder to type.
You know there's all sorts of odd characters that you can do.
There's square brackets.
There's curly brackets.
There are, you know, brackets or quotes for other languages.
So you can use those.
There's all sorts of different things you may want to enclose text in for different
reasons.
You can create scripts for these.