Use Case
-
Select a Sentence in Apple Pages app that can contain periods
- This could easily be modified for use with any app that supports the Finder Pasteboard
- Text Cursor May Now be anywhere within the target Sentence (start, middle, or end).
- Sentence may end in any of the common punctuation marks
.?!
- This could be easily changed by modifying the RegEx:
([A-Z].+?(?=(?:[\.?!]\h+[A-Z])|[\.?!]$)[\.?!])
- See RegEx101.com Extract Sentence from Paragraph for details and explanation
- This could be easily changed by modifying the RegEx:
- See the Assumptons in the below Release Notes for the definition of a Sentence.
. -
Limitations:
- Note: This Macro is designed only for the English language and may or may not work in other languages.
- Macro will yield a false positive IF an abbreviation is immediately followed by a capital word that is NOT the start of a new sentence, as in:
"abbrev. KM"
This Macro was built in response to:
Select a sentence in Pages
UPDATED: 2019-02-17 21:19 GMT-6
Output Example
MACRO: Pages -- Select Sentence With Cursor Within Sentence [Example]
~~~ VER: 2.0 2019-02-17 ~~~
Changes:
- Text Cursor may now be located anywhere within (start, middle, end) of Target Sentence.
DOWNLOAD:
Pages -- Select Sentence With Cursor Within Sentence [Example].kmmacros (24 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
ReleaseNotes
Author.@JMichaelTX
PURPOSE:
-
Select Sentence in Pages app
- Uses RegEx and Find Pasteboard
- Text Cursor May be at Start, Middle, or End of Sentence
REQUIRES:
- KM 8.2+
- macOS 10.11.6 (El Capitan) or later
NOTICE: This macro/script is just an Example
- It has had very limited testing.
- You need to test further before using in a production environment.
- It does not have extensive error checking/handling.
- It may not be complete. It is provided as an example to show you one approach to solving a problem.
How To Use
- Open Apple Pages with a document of interest.
- Position Text Cursor at the Start, Middle, or End of a Sentence you want to select.
- Trigger this macro.
- It will then use RegEx to identify the Sentence within the remainder of the paragraph. See Assumptions below for the definition of a Sentence.
- Use the Find Pasteboard to select that Sentence.
MACRO SETUP
-
Carefully review the Release Notes and the Macro Actions
- Make sure you understand what the Macro will do.
- You are responsible for running the Macro, not me. ??
.
- Assign a Trigger to this maro..
- Move this macro to a Macro Group that is only Active when you need this Macro. Most likely this is for the Pages app.
- ENABLE this Macro.
Assumptions
- That the user has positioned the text cursor within (Start, Middle, End) of the Sentence.
- The Sentence ENDS with one of the following punchuation:
.?!
- Followed by another Sentence that identified by the following after the END of the first Sentence:
- One or more horizontal whitespace characters
- A Capital letter
OR - The END of the string
- Followed by another Sentence that identified by the following after the END of the first Sentence:
TAGS: @Pages @RegEx @Find @Pasteboard @Select
USER SETTINGS:
- Any Action in magenta color is designed to be changed by end-user
ACTION COLOR CODES
- To facilitate the reading, customizing, and maintenance of this macro,
key Actions are colored as follows: - GREEN -- Key Comments designed to highlight main sections of macro
- MAGENTA -- Actions designed to be customized by user
- YELLOW -- Primary Actions (usually the main purpose of the macro)
- ORANGE -- Actions that permanently destroy Variables or Clipboards,
OR IF/THEN and PAUSE Actions
USE AT YOUR OWN RISK
- While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
- If you have any doubts or questions:
- Ask first
- Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.