MacMost Q&A Forum • View All Forum QuestionsAsk a Question

How Do I Enclose Selected Text In Pages With Quotes With a Shortcut?

I would like to be able to select a string of text in Pages and use a shortcut to enclose it with quotes without typing a quote at the beginning of the string, moving to the end of string, typing the end quote. Same for parentheses and brackets. Maybe using Automator?
—–
Stephen Ferris

Comments: 4 Responses to “How Do I Enclose Selected Text In Pages With Quotes With a Shortcut?”

    5 years ago

    Yes, you can do that with Automator.

    In automator, create a new Quick Action file. This used to be called a Services script.

    Then select "rich text" as what the workflow receives. Set it to "Pages" for the application, or "any application" if you wish. Check "Output replaces selected text."

    Then as the only element in the Automator file, use "Run JavaScript." Then paste this script in there:

    function run(input, parameters) {
    input = "“"+input+"”";
    return input;
    }

    So it is really just the one line to add, as the rest are there by default. That one line sets the input to the input, plus a curly quote before and one after.

    Then save it. It should save to your Library/Services folder automatically.

    In Pages, go to Pages, Services and see if you see it there. If not, choose Services Preferences... at the bottom of that menu. Then find it and make sure it is enabled. You can add a keyboard shortcut here too.

    I just tried this and it works very well. I'll have to make it into an episode.

    Stephen Ferris
    5 years ago

    Thanks for the quick response. I carefully followed your steps, but I get an error message having to do with JavaScript when I click on the Quick Action in Services under Pages. The error message is: The action “Run JavaScript” encountered an error: “Error on line 2: SyntaxError: Invalid character '\u201c'”. Line 2 is: input = ““” +input+”””; Is one of the quote characters incorrect?

    Much enjoy your blog and the three courses I've purchased.

    5 years ago

    Stephen: The quotes should be "”" and "”". So straight quotes, curly, straight for each. Straight quotes are what JavaScript uses to enclose a string of characters. Looks like copying and pasting to the site made them all curly. I'll correct that.

    Stephen Ferris
    5 years ago

    Thanks. Works fine now.

Comments Closed.