Does anyone have a macro for Scrivener in Mac OS that will place quotation marks at the beginning and end of a line?
I once created a Macro in Word, which would place quotation marks at the beginning of a line, move to the end and place quotes there as well. As I recall, it then moved the cursor to the next line. Suppose I could compose in Word, but that sort of defeats the purpose, doesn’t it?
(I know someone is going to recommend Keyboard Maestro which is a bigger and more complex tool than I need.) (When the tool doesn’t make work easier, it fails to fit the definition of a “tool.”)
If you mean the beginning and end of a sentence or paragraph (not line), that may be possible with Keyboard Maestro. If it’s possible with built-in macOS features, I doubt it will be simple to accomplish, and you may not end up thinking the tool made things easier. Automator defeated all my efforts to use it, but KM made things easier from the very first day.
I use TextExpander for some things, including a snippet with “” as the shortcut. The shortcut quotes don’t have to be curly, and the result leaves the cursor between smart quotes. Hence I can always start dialogue with that shortcut and won’t have to remember the closing quote.
You can’t make a keyboard macro without a keyboard macro app! It just so happens Word has its own embedded custom programming language. Scrivener (like most apps) does not. MacOS Keyboard Prefs only has a built-in facility for assigning keys to menu items. Applescript can simulate keystrokes (and do many other things), but you still need to figure a way to invoke your Applescript itself with a keystroke. (Applescript can only work the UI of Scrivener from outside, not call any internal function calls.)
IF you wanted to move by sentences: I don’t think Scrivener has a key command to go to the end/beginning of a sentence (which I suppose would be a tricky algorithm). So, you do not have something to build off for a by-sentence key macro.(*)
But Scrivener does have key commands to move to beginning/end of paragraphs (and by word). So, you could build a macro off that, if it suited you. See note 1 above.
(*) drmajorbob seemed to suggest Scriv does have beg/end sentence keystrokes and not a beg/end of soft-warp line keystroke. Maybe he knows something I don’t, but I think that actually gets things backwards. Cf. Section 15.2.1 of the Scrivener manual.
No, I didn’t. I only suggested Keyboard Maestro might do the trick somehow.
You’d need a macro that selects the entire paragraph (with a triple-click), then searches the paragraph for sentences. If you only want to edit one sentence (where the cursor was when you invoked the macro), that gets complicated but may be possible with some work. You’d have to leave a marker for that cursor position and use it to identify the target sentence. I wouldn’t want to do any of that.
I think it would be just as difficult (or more so) to do it with a macOS tool.
While there isn’t a pair of direct sentence navigation shortcuts like in Vim, for the purposes of macros (and those that don’t mind two-key operations), you can achieve this effect simply:
Bind a custom keyboard shortcut to the Edit ▸ Select ▸ Select Sentence menu command (for this purpose, the option that doesn’t include the space would work best).
Now to navigate we employ a simple trick that works for any selection at all: hit the Left arrow to move the cursor to the start position of the selection, and the Right arrow to the end.
My guess though is that one would want a more arbitrary tool than that, where selection is probably the one thing you do as a human, and let the computer sort out the manual labour of inserting punctuation marks around the selection.
I’ve made macros like that before, it’s fairly simple:
Cut the selection.
Modify the pasteboard to include the desired prefix and suffix, or if you find that damages Scrivener’s special pasteboard data (styles, inline annotations, etc.), then substitute this step for inserting the prefix and suffix into the editor, left-arrowing, and then…
One would not need to learn macro software to achieve this though. Most text expansion utilities have the ability to insert the clipboard into the expansion. So cutting the text and then typing in something like !qt (for “quote text”) would suffice.
What I meant was, the end of the spoken line (sentence) OR the end of a short series of dialogue, to find the place for close quotes. I’m reconciled now that I would need a macro app to do this. To be frank, after taking a look at Keyboard Maestro, I will not be doing this. It’s a little more difficult task than I want to take on.
That’s brilliant. One of those “hidden in plain sight” power commands! I had completely forgotten about it… This way it’s incredibly easy to automate this quotation macro. Like so, in an Alfred workflow:
F3 is my key assigned to the “Select Sentence” menu item in Scrivener. F4 triggers the Alfred workflow (if Scrivener is the active app). I made both “Copy to Clipboard” steps “transient”, so that they don’t leave any temporary items in the Clipboard History. They just insert » and « anyways. Had to introduce a 150 milliseconds delay after the first copy operation. Works like a charm, without touching any Scrivener formattings. Only drawback: Afterwards the cursor is placed behind the sentence.
ADD: Maybe @drmajorbob can create a KM macro based on the idea. Should be easy-peasy.
I know how you feel. I found KM intimidating and overwhelming when I first started using it.
Give this a try – go to this web page, and click the button “Watch Promo” – it’s a free introductory lesson in KM from MacSparky, from his Field Guide course.
I highly recommend Keyboard Maestro as essential kit, especially for Scrivener. And the MacSparky Field Guide made learning and using KM easy and pain-free.
The real power of KM for a writer is that it lets you build simple little macros to make your process a little smoother. Those little improvements accumulate to make your writing faster, easier and better.
I can’t overstate how welcoming and helpful the KM user group is. There are a crowd of ultra-friendly, super-helpful KM ninjas there who will both solve your problem and teach you how to do it next time.
I don’t understand that macro flowchart: Select sentence. Move insertion point to start of sentence. Copy to clipboard. There would be nothing to copy at step three. Ditto for the second half.
I would scheme this out as: Select sentence. Move insertion point to beginning of sentence. Type prefix char/string. Select sentence. Move insertion point to end of sentence. Type post-fix char/string.
In KM (assuming ‘Select Sentence’ menu item is assigned to F3):
True, I understand how this is confusing. Maybe there’s a better way to do it, but what this function actually does (if told) is inserting the text (quotation mark) into the active app’s editor at cursor position.
EDIT: Basically the same as your workflow. But yours sends keystrokes (I could have done that, too).
Here’s a Keyboard Maestro macro that uses AmberV’s suggestion to do what you asked. Just unzip it and double click the uncompressed file to install it in Keyboard Maestro. The trigger is Cmd-Opt-’ with your cursor in the sentence you want to quote.
All it does is Select the Sentence, Copy it to the clipboard, Type a double quote character, Paste the clipboard (to get your sentence back) and Type another quote character. (I might have built it by simply recording those steps with Keyboard Maestro but I didn’t try. I could be that easy.)
It’s a simple demo of AmberV’s solution. But I might like it to work with selected text (which would be more flexible than a sentence) and have alternates for single quotes (or even alternate quoting).
I might also like to remove the sentence from the clipboard at the end of the macro, but for safety’s sake, I left it in.
Here’s a revised version which works on either a selection (and hence potentially not just in Scrivener) or, if you don’t have text selected, Scrivener’s sentence detection.
I use it, like drmajorbob, from a palette (so the single Q trigger is safe). If you hold down the Option key while clicking on the menu item or typing Q while the menu item is open, you’ll get single quotes.
They will be smart quotes if that’s what your Scrivener document is expecting. Or straight quotes if that’s what you prefer.
I would like to suggest that it is better not to overwrite your text with a macro unless absolutely necessary. In this case, there is no reason to copy the select text to the clipboard and overwrite it. See the KM macro I detailed a couple posts up.