Macro for writer needed for conditional capitalizing

Hi guys. I do offline transcription and closed captioning for lectures, documentaries, etc. When there are multiple speakers, we differentiate them with >> (double chevrons). I need LO Writer to automatically capitalize after putting a >> for the beginning of the next sentence.

For example:

>> We have a lot to do today.
>> Okay, I'm ready. Let's get to it.

So, basically I need the text to see >> as some sort of punctuation to trigger autocaps. Any help is GREATLY appreciated, as I’m a noob when it comes to writing macros. (Would it be possible to do a Record Macro for this?)

Thanks guys

Cam!

(Edited: Code enhanced with respect to the comments below by @Cam1. The Sub will now recreate the view cursor as it was before the run.)

“Would it be possible to do a Record Macro for this?”
I didn’t think so but tried and it worked.
To be clear: I had to do a ‘F&R’ searching for a RegEx and performing a ‘Find All’. The text pieces found were changed to upper case then. The procedure will not be triggered automatically, but will process the complete text if called once after the typing. A second run will not change anything again.
The RegEx I used was >> {0,1}[:alpha:] meaning the “some sort of punctuation” character pair followed by zero or one spaces and one ordinary character. You may abandon the optional space or remove the quantifier to get exactly one.
I did not care about returning to any specific position. The changed text portions remain selected on ‘End Sub’.

REM  *****  BASIC  *****
Option Explicit

Sub ChangeToUpperAfterSpecialCharacterPair

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

REM Start manual insertion 1
Dim theDoc As Object, theViewCursor As Object, theOldStart As Object, theOldEnd As Object
theDoc=ThisComponent
theViewCursor=theDoc.CurrentController.ViewCursor
theOldStart=theViewCursor.GetStart
theOldEnd=theViewCursor.GetEnd
REM End manual insertion 1

dim args1(21) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.SearchFiltered"
args1(4).Value = false
args1(5).Name = "SearchItem.Backward"
args1(5).Value = false
args1(6).Name = "SearchItem.Pattern"
args1(6).Value = false
args1(7).Name = "SearchItem.Content"
args1(7).Value = false
args1(8).Name = "SearchItem.AsianOptions"
args1(8).Value = false
args1(9).Name = "SearchItem.AlgorithmType"
args1(9).Value = 1
args1(10).Name = "SearchItem.SearchFlags"
args1(10).Value = 65536
args1(11).Name = "SearchItem.SearchString"
args1(11).Value = ">> {0,1}[:alpha:]"
args1(12).Name = "SearchItem.ReplaceString"
args1(12).Value = ""
args1(13).Name = "SearchItem.Locale"
args1(13).Value = 255
args1(14).Name = "SearchItem.ChangedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.DeletedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.InsertedChars"
args1(16).Value = 2
args1(17).Name = "SearchItem.TransliterateFlags"
args1(17).Value = 1280
args1(18).Name = "SearchItem.Command"
args1(18).Value = 1
args1(19).Name = "SearchItem.SearchFormatted"
args1(19).Value = false
args1(20).Name = "SearchItem.AlgorithmType2"
args1(20).Value = 2
args1(21).Name = "Quiet"
args1(21).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

dispatcher.executeDispatch(document, ".uno:ChangeCaseToUpper", "", 0, Array())

REM Start manual insertion 2
theViewCursor.GotoRange(theOldStart,false)
theViewCursor.GotoRange(theOldEnd,true)
REM End manual insertion 2

End Sub

The resulting Sub is a wee little monster. But what of it?

See also this demo.

AWESOME!!! Thank you SO much. This works perfectly! All I have to do is assign a shortcut button and I’m all set. Cool beans and thanks again!

Cam!

and I also added

dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array())

at the end to deselect the text so I won’t accidentally overwrite it.

Is there a way to have the cursor return to the last place that I was typing before I ran the macro?

Yes, of course. If you are interested in the ways the LibO API works and how it is accessd in BASIC, you should read the famous texts (“Book” and “Useful Macro Information” )by Andrew Pitonyak.

Awseome! Thank you guys!