KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Dragon command that will prepend hyphen in front of every line of selected text
Topic Summary:
Created On: 02/20/2021 01:28 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 02/20/2021 01:28 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 130
Joined: 09/03/2020

Frequently, I need to turn the several lines of text into a bulleted list. For example, I will want to turn this:

 

list item 1

list item 2

list item 3

 

Into this:

 

- list item 1

- list item 2

- list item 3

 

I created a command that will send the keys  "-{down}{Home}" X amount of times,  which is not ideal because it requires me to know how many items I am listing. For example, I would have to say, "bullet list down 3"  in order  to prepend the - character 3 times. If it's a lot of text, then I need to run the command multiple times or sit there counting lines. I have better things to count!

 

so what I want is a command that will:

 

- read the currently selected text

- count the amount of linebreaks in that text

- insert a "-" character after every line break (i.e., at the beginning of every)

 

I have no idea how to go about this. Is this possible?



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.



 02/20/2021 01:40 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

I think it's possible, although the implementation might be different than what you describe. What application or applications does this need to work in?

If Word, are "soft" hyphens OK? I'm referring to hyphens that are symbols that look like hyphens, but can't be acted on directly. Similar to bullet points in Word.
 02/20/2021 04:14 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 130
Joined: 09/03/2020

It needs to work outside of Dragon friendly apps; simple text editors without any Select-and-Say functionality.

In Microsoft Word, I can create these lists easily by using the tools built into Microsoft Word, so this command would not use in Microsoft Word.



-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 02/20/2021 08:07 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

This sort-of works in Notepad. But you have to be careful about where the selection starts and ends. It's not bulletproof, but it was a fun 20 minute project for a Saturday night!

No doubt a more experienced script-writer will come up with a better, more elegant solution.

Sub Main
Dim x As String
SendKeys "^c", True
Wait .5
Let x = Clipboard
Wait .5
Let x = Replace(x, Chr$(10), "- ")
SendDragonKeys x
End Sub
 02/21/2021 12:52 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

This version is less fussy about where the selection starts.


Sub Main
' Prepend "- " to each line in a selection
' x is the selection
' y is an individual character within x
' z is a reconstructed version of x, with a hyphen starting each line

Dim x, y, z As String
Dim Lengthx, Count As Integer

SendKeys "^c", True
Wait 0.3

Let x = Clipboard
Let Lengthx = Len(x)
Let Count = 1
Let z = "- " ' Assume first character needs to be a hyphen

While Count <= Lengthx
Let y = Mid(x, Count, 1)
If y = Chr$(10) Then
Let y = "- "
End If
z = z & y
Count = Count + 1
Wend

Clipboard z
SendKeys "^v", True
End Sub
 02/21/2021 10:40 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

Finally, a hybrid between the two, which I think is the best so far.

Sub Main
' Prepend "- " to each line in a selection
' x is the selection

Dim x As String

SendKeys "^c", True
Wait .3

Let x = Clipboard
Wait .3

Let x = "- " & Replace(x, Chr$(10), "- ")

Clipboard x
SendKeys "^v", True
End Sub
 02/22/2021 02:18 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 130
Joined: 09/03/2020

Thank you, this last one works great in my desired application.

I don't totally understand the code. "Dim x as string" -- what else would it be aside from a string? What does the dim function do exactly?

I looked it up, but somebody probably needs to explain to me like I'm five.

-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.

 02/22/2021 02:30 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

The "Dim" statement means that "x" is a string and not something else that looks like a string, like a number. (The number "123" could be a string or an integer. If it's an integer, I can add another number to it. But if it's a string, I can't use it for math.)

Sometimes "Dim" statements are optional. They can be omitted and everything works fine. It's considered good form to include them.
 02/25/2021 11:11 PM
User is offline View Users Profile Print this message

Author Icon
wristofdoom
Senior Member

Posts: 130
Joined: 09/03/2020

Thanks Alan. I've extended your command to do the same thing but with different Markdown formatting elements. I think anybody who uses markdown frequently would benefit from the full command, so I'll post what I have here.


Command name:

MD all <md_el>

 

list values For

Note: "md_el" Is my shorthand for "markdown element"

List items:

Checkbox
quote
dash

code:

Sub Main
' Prepend y to each line in a selection
' x is the selection

Dim x As String

oldClipboard = Clipboard ' Save the current clipboard so we can get it back later
Wait 0.1
SendKeys "^c", True
Wait .3

Let x = Clipboard

    Select ListVar1
    Case "dash"
        Let y = "- "
    Case "quote"
        Let y = "> "
    Case "checkbox"
        Let y = "- [ ] "
    End Select

    Wait .3

Let x = y & Replace(x, Chr$(10), y)

Clipboard x
SendKeys "^v", True

Wait 0.1
Clipboard oldclipboard ' Restore the old clipboard

End Sub
'https://www.knowbrainer.com/forums/forum/messageview.cfm?catid=12&threadid=35440


-------------------------

Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017.



Statistics
31978 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 0 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 539 guests browsing this forum, which makes a total of 539 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2021 FuseTalk™ Inc. All rights reserved.