'Go to end of sentence' script

Hi, everyone. I’m new to this, but I don’t mind teaching myself what I might need to know. I’ve recently moved from MS Word for Mac (where I created a bunch of VBA macros to do things I wanted) to a program called Scrivener, and it’s missing one crucial feature: a keyboard command to go to the end of (or beginning of) the current sentence. There’s no scripting language built into the program, and Quickeys can’t do it, but I wonder if there’s some other way? It would involve searching for any sentence delimiter (.?! etc., possibly with quotation marks as well) and moving the cursor there, as well as, ideally, being able separately to select the intervening text.

Many thanks for any guidance.

Model: MacBook Pro 2015
Browser: Safari 602.1.50
Operating System: Mac OS X (10.10)

Hi arthgold. Welcome to MacScripter.

If Scrivener itself isn’t scriptable, I don’t think there’s a sensible way to do what you want. :frowning:

It does seem odd that there’s no concept of a sentence in Mac OS keystrokes or AppleScript text handling. :confused:

These should work in any RTF-aware application (click the ‘text’ category’).

How do you define a sentence?

This is a sentence. :wink:

Fortunately, I don’t need to define one for scripting purposes in this case. But the implication in arthgold’s query is that MS Word has keystrokes for moving the cursor to the beginning or end of a sentence, so presumably someone’s come up with a method. No doubt it’s completely impotent against most modern SMS, e-mail, and Web content. :wink:

Actually, I think Word regards that as two sentences :wink:

I only have an old version of Word, and its sentence selection algorithm seems very simple/fragile. I was just musing how to do it if you could get at the text, given that AS doesn’t cover it, and the obvious Cocoa method is off-limits because it requires blocks. I can see a way that’s probably very locale-influenced, but not a “neutral” way.

Microsoft Word has an VBA object sentences which is very basic. It will move to the next sentence terminator if followed by a whitespace. You can bind a shortcut to this command and save it in your normal document to enable it everywhere. It simplicity will show it’s flaws when using it for the next sentence:

“According to the sporting regulation (Art. 27.6) it is not allowed to swirl around the track to defend position.”

That’s quite difficult. Defining sentences is done with character counting, pattern matching and using the spelling dictionaries. Using all three methods together comes close to a good sentence prediction but is never 100% safe. Therefore there are no standards and the outcome may differ between implementations.

Many thanks to all of you for your thoughts on this. I’m going to assume it’s not likely to happen, but I really appreciate the time you’ve put into it. I’m new to BBs like this, and I’m really impressed with the sense of community. Thanks.

Yes, that’s what I was suggesting.

Thanks for your sample – the three Cocoa methods I tried (enumerating substrings both standard and localized, plus getting linguistic tags) all failed the test.