KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Shortening the italicize command
Topic Summary: Is it possible to create a macro or make a script to customize (shorten) the italicize command?
Created On: 02/19/2021 04:10 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Shortening the italicize command   - dinotalking - 02/19/2021 04:10 PM  
 Shortening the italicize command   - Alan Cantor - 02/19/2021 08:27 PM  
 Shortening the italicize command   - Edgar - 02/20/2021 10:55 AM  
 Shortening the italicize command   - Alan Cantor - 02/20/2021 12:36 PM  
 Shortening the italicize command   - Edgar - 02/21/2021 10:27 AM  
 Shortening the italicize command   - dinotalking - 02/22/2021 08:13 PM  
 Shortening the italicize command   - dilligence - 02/22/2021 10:38 PM  
 Shortening the italicize command   - Alan Cantor - 02/22/2021 11:55 PM  
 Shortening the italicize command   - dinotalking - 02/23/2021 01:19 PM  
 Shortening the italicize command   - dilligence - 02/23/2021 04:12 PM  
 Shortening the italicize command   - dinotalking - 02/24/2021 10:43 AM  
 Shortening the italicize command   - Alan Cantor - 02/24/2021 10:45 AM  
 Shortening the italicize command   - Alan Cantor - 02/24/2021 10:54 AM  
 Shortening the italicize command   - Alan Cantor - 02/24/2021 11:39 PM  
 Shortening the italicize command   - dinotalking - 02/27/2021 01:42 PM  
 Shortening the italicize command   - Alan Cantor - 02/27/2021 04:50 PM  
 Shortening the italicize command   - dinotalking - 03/01/2021 11:03 AM  
 Shortening the italicize command   - Alan Cantor - 03/01/2021 11:48 AM  
 Shortening the italicize command   - dinotalking - 03/01/2021 12:14 PM  
 Shortening the italicize command   - Alan Cantor - 03/01/2021 12:30 PM  
 Shortening the italicize command   - dinotalking - 03/01/2021 01:25 PM  
Keyword
 02/19/2021 04:10 PM
User is offline View Users Profile Print this message

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Hello,

I’ve managed to add some commands to Dragon that I like, such as the shortened terms "OQ" and "CQ" for open quotation marks and close quotation marks. One thing I’ve never known how to do is simplify the standard “italicize” command. The main way to do it, as you know, is to say "Italicize last x words," which is a bit cumbersome. Is there a way to create a macro or a bit of scripting to simplify this – i.e. so that one might say something like "i6" and have that recognized as "italicize last six words"? I do a lot of note-taking on books (I’m a retired academic), so I would be glad to shorten the italicize command, which comes up pretty often for book titles and whatnot. Thanks.

Al



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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

 02/19/2021 08:27 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

In Dragon circa 2009, you could add lines like these to options.ini:

enx Italicize XYZ Command=Eye
enx Italicize From XYZ Command=Eye

"enx" refers to the language you are using (English in this example).

"Eye" is my substitute command for "Italicize"

So I could say "Eye language you are using" (to italicize the four words, above) and "Eye from refer to example" (to italicize a longer phrase).

Not sure these work anymore. If they do work, I wouldn't use "eye" as the replacement, as that would be an invitation to undesirable side effects. The case of words might matter. I might try these:

enx italicize XYZ command=eye yi
enx italicize from XYZ command=eye yi

If these work, you'd be able to say "eye yi Not sure these work" but probably not "eye yi last four words."
 02/20/2021 10:55 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1104
Joined: 04/03/2009

It should certainly be possible to do this with a script but the script might have to be "application-specific". Imagine that in one application you highlighted a selection of words and then pressed "control + i" to italicize that selection. In another application, after highlighting the selection, you pressed "shift + ctrl + j" to achieve the same italization. It's fairly easy to write a script that parses "the last XXX words" (where XXX is some numeral) to figure out the number of words desired. Most applications also use the exact same keypress sequence to select a given number of words (either forward or backward). So, once you figure out what the keypress sequence is to italicize the rest is pretty easy.

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

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 02/20/2021 12:36 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007


Most applications also use the exact same keypress sequence to select a given number of words (either forward or backward).



I wish navigating and selecting word by word was consistent. It isn't.


The key sequences to navigate and select by word is the same in MS-Word, WordPad, DragonPad, the Dictation Box, and Excel. But the sequences are different in Notepad and in browsers.

In some web applications, the developers have created their own navigation and selection methods, so key sequences work differently or don't work... period!

I think the variations are most conspicuous around the handling of punctuation marks and line/paragraph breaks. For example: Is the punctuation mark at the end of a sentence or phrase part of the word that it clings to? For Notepad, the answer is "yes." For Word, the answer is "no."

(Starting with the insertion point at the end of the previous paragraph, select the entire sentence by pressing Ctrl + Left arrow SIX times in Notepad, or NINE times in MS-Word!)

During the 1990s, I developed a set of rules for word-by-word navigation and selection. I implemented the rules in the DOS-based word processor I used at the time. I thought my method was promising -- it shaved days, maybe weeks, from the process of drafting, editing, and polishing my Masters thesis. The method was internally consistent, and logical (or so I thought.) I showed my method around, but at that time the geeks in my life were going gaga for doing everything via mouse. So I was the sole beneficiary of my method. When I started using Windows in the mid-1990s, I was disappointed about the inconsistencies of word-by-word navigation and selection across programs. 25 years later, the inconsistencies have multiplied. I think that's because most developers don't take seriously keyboard-only access.
 02/21/2021 10:27 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1104
Joined: 04/03/2009

Originally posted by: Alan Cantor
Most applications also use the exact same keypress sequence to select a given number of words (either forward or backward).
I wish navigating and selecting word by word was consistent. It isn't.

So true! That is why I mentioned that some of the work would have to be application-specific. If trying to generalize something that will work for everyone everywhere, the task would be daunting. Fortunately, most of individuals don't use a whole lot of editors that are capable of italicizing. One general solution that works in Word (or whatever their primary rich text editor is), which demonstrates the concept, would probably be good enough and easily extended by minor modifications of the selection section of the code for application-specific situations.



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

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

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

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Thanks for your insights, Alan and Edgar. Much obliged.

Al

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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

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

Author Icon
dilligence
Top-Tier Member

Posts: 1293
Joined: 08/16/2010

Originally posted by: dinotalking

Is there a way to create a macro or a bit of scripting to simplify this – i.e. so that one might say something like "i6" and have that recognized as "italicize last six words"? 

 

 

Assuming you are working in applications that follow the standard Ctrl+i convention (Word, WordPad, DragonPad, Apache Open Office Writer etc.) this fast DVC command works (you can use any list you want, in this case I used the standard 1to10 list):

 

 

IT <amountofwords>

 

If _arg1 = "1" then SendKeys "{Ctrl+Shift+Left}{Ctrl+i}"

If _arg1 = "2" then SendKeys "{Ctrl+Shift+Left 2}{Ctrl+i}"

If _arg1 = "3" then SendKeys "{Ctrl+Shift+Left 3}{Ctrl+i}"

If _arg1 = "4" then SendKeys "{Ctrl+Shift+Left 4}{Ctrl+i}"

If _arg1 = "5" then SendKeys "{Ctrl+Shift+Left 5}{Ctrl+i}"

If _arg1 = "6" then SendKeys "{Ctrl+Shift+Left 6}{Ctrl+i}"

If _arg1 = "7" then SendKeys "{Ctrl+Shift+Left 7}{Ctrl+i}"

If _arg1 = "8" then SendKeys "{Ctrl+Shift+Left 8}{Ctrl+i}"

If _arg1 = "9" then SendKeys "{Ctrl+Shift+Left 9}{Ctrl+i}"

If _arg1 = "10" then SendKeys "{Ctrl+Shift+Left 10}{Ctrl+i}"

 

I used the “IT” prefix because I previously used “I” in another command and now Dragon is not responding to that anymore, but you can probably use it.

 

Here’s what it looks like in my Command Browser:

 

 

 



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

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


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

Nice! To force the same command to deselect the selection and restore the cursor position, try this DVC script:

SendKeys "{Ctrl+Shift+Left " & _arg1 & "}"
SendKeys "{Ctrl+i}"
SendKeys "{Right}"

Be careful about deploying this command in Notepad, which doesn't support italicized text. Instead, pressing Ctrl + I appears to insert a tab character. (Maybe "I" stood for "Indent" during DOS Days?)



 02/23/2021 01:19 PM
User is offline View Users Profile Print this message

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Thanks to Dilligence and Alan! This looks like the ticket, and I'll add it in today. Have wanted to shorten the italicize command for a long time, so this is fantastic. By the way, the earlier problem I mentioned several days ago in my initial post on this forum -- the spotty quality of how Dragon is handling numbers/numerals, I've come around to simply unchecking the auto-correct option for numbers "greater than or equal to...." At least that choice seems to be stable from one firing-up of Dragon to the next, and it offers the benefit of typing terms like "fourteenth century" spelled out fully and not having to correct them. It's easy enough just to say "numeral 2" when I want "2" rather than "two." Thanks again, much obliged for the scripting help.

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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

 02/23/2021 04:12 PM
User is offline View Users Profile Print this message

Author Icon
dilligence
Top-Tier Member

Posts: 1293
Joined: 08/16/2010

Following Alan's approach, you can also catch it in a DVC loop (you can use the same list and you can replace "c" with anything else):

 

c = _arg1

Do Until c = z

SendKeys "{Ctrl+Shift+Left}"

c = c-1

Loop

SendKeys "{Ctrl+i}"

SendKeys "{Right}"



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

 02/24/2021 10:43 AM
User is offline View Users Profile Print this message

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Hello,

Here's what I input into Dragon's MyCommands box, but when I try to save it, I get a message telling me "please correct syntax error for your macro before saving." Can someone let me know where the mistake lies? (I picked "advanced scripting" as the option): between sub (main) and end sub, I have:

If_arg1 = "1" Then SendKeys "{Ctrl+Shift+Left}-{Ctrl+i}"
If_arg1 = "2" Then SendKeys "{Ctrl+Shift+Left 2}-{Ctrl+i}"
If_arg1 = "3" Then SendKeys "{Ctrl+Shift+Left 3}-{Ctrl+i}"
If_arg1 = "4" Then SendKeys "{Ctrl+Shift+Left 4}-{Ctrl+i}"
If_arg1 = "5" Then SendKeys "{Ctrl+Shift+Left 5}-{Ctrl+i}"
If_arg1 = "6" Then SendKeys "{Ctrl+Shift+Left 6}-{Ctrl+i}"
If_arg1 = "7" Then SendKeys "{Ctrl+Shift+Left 7}-{Ctrl+i}"
If_arg1 = "8" Then SendKeys "{Ctrl+Shift+Left 8}-{Ctrl+i}"
If_arg1 = "9" Then SendKeys "{Ctrl+Shift+Left 9}-{Ctrl+i}"
If_arg1 = "10" Then SendKeys "{Ctrl+Shift+Left 10}-{Ctrl+i}"
SendKeys "{Ctrl+Shift+Left " & _arg1 & "}"
SendKeys "{Ctrl+i}"
SendKeys "{Right}"





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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

 02/24/2021 10:45 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

Remove the hyphens before {Ctrl+i}



 02/24/2021 10:54 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

Advanced Scripting uses a different syntax for SendKeys.

1. Change "SendKeys" to "SendDragonKeys" or "SendSystemKeys"

or

2. Change Ctrl to "^" and Shift to "+"

E.g.,

SendKeys "+^{Left 2}"

This probably won't make a critical difference, but it's considered good form to do this:

SendKeys "+^{Left 2}", True
 02/24/2021 11:39 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

Dinotalking,

I took another look at the code you tried as an Advanced Scripting command instead of as a DVC command, and I've got a few suggestions:

Your code won't work as an Advanced Scripting command unless you make an additional change. It will be easier to keep it as a DVC command. (But if you want to know about the other change you would need to make for the code to work as an Advanced Scripting command, just say so.)

Choose either Dilligence's ten-line code example, my three-line code example, or Dilligence's seven-line code example. But don't try to mix-and-match them. At least not yet! The last two code examples do the same thing in slightly different ways, and both are likely going to work. It doesn't matter which one.

Select the code sample you decide to use from this forum, copy it, and paste it into the Command Browser. Retyping it may lead to errors.

Don't be discouraged if the command doesn't, at first, do exactly what you think it's going to do. I think it's fair to assume that all of us who are "into" Dragon scripting learned many hard lessons through a long process of trial-and-error experimentation!



 02/27/2021 01:42 PM
User is offline View Users Profile Print this message

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Alan,

Thanks for the insight. I'm still trying to get the code to work, so I would be very interested to know what additional change I'd need to make for advanced script. It's been years since I did anything with programming, so even my novice understanding is still rusty!

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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

 02/27/2021 04:50 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

Here it is as an Advanced Scripting command:

Command name = I T <1-20>

The list <1-20> consists of:

1
2
3
4
...
20


Sub Main
Dim x as String
Let x = ListVar1
SendDragonKeys "{Ctrl+Shift+Left " & x & "}"
SendDragonKeys "{Ctrl+i}"
SendDragonKeys "{Right}"
End Sub



 03/01/2021 11:03 AM
User is offline View Users Profile Print this message

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Hello Alan and all,

That works wonderfully, thanks. I just added a line towards the end to de-italicize the text following the italicized section, so the final version of the shortcut italicize command looks like this:

Sub Main
Dim x as String
Let x = ListVar1
SendDragonKeys "{Ctrl+Shift+Left " & x & "}"
SendDragonKeys "{Ctrl+i}"
SendDragonKeys "{Right}"
SendDragonKeys "{Ctrl+i}"
End Sub

One should keep in mind that MS Word counts punctuation as a "word," so if, say, a book title contains a comma or a colon, etc., that counts as a word. If you want to italicize the title Henry VIII, or, All for Love it would be counted as 8 words, and you would say "IT 8" even though there are only six actual words.

That brings up a question -- what code should be added if you want to adjust the command so that it will ignore punctuation for the purpose of counting, but still italicize that punctuation since it's part of the phrase that needs italicizing? In the Henry VIII example, the commas would be italicized since they are part of the title. The reason for making the adjustment would be that it's easier to ignore the commas and whatnot if you're counting the words of a longish phrase or title.

Regards,

Al

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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

 03/01/2021 11:48 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007


what code should be added if you want to adjust the command so that it will ignore punctuation for the purpose of counting, but still italicize that punctuation since it's part of the phrase that needs italicizing? In the Henry VIII example, the commas would be italicized since they are part of the title. The reason for making the adjustment would be that it's easier to ignore the commas and whatnot if you're counting the words of a longish phrase or title.


It's a good question. The challenge would be that different applications handle punctuation differently when selecting by word. Some apps include punctuation as part of the word, some don't.
 03/01/2021 12:14 PM
User is offline View Users Profile Print this message

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Yes, I see. What if you're only planning to use it for Microsoft Word?

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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

 03/01/2021 12:30 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4027
Joined: 12/08/2007

Something like this might help. But I think you may find this script will occasionally give unpredictable results.

One can spend a lot of time trying to "tweak" a script like this to work under every imaginable condition, but even at this relatively undeveloped stage, the time saving may already be beyond the point of diminishing returns. Considering taking those punctuation marks into account when issuing the existing command.

Sub Main
Dim x, y, z As String
Dim Diff As Integer

Let x = ListVar1
SendDragonKeys "{Ctrl+Shift+Left " & x & "}"

SendDragonKeys "{Ctrl+c}"
Wait .1
Let y = Clipboard

Let z = y
Let z = Replace(z, ",", "")
Let z = Replace(z, ".", "")
Let z = Replace(z, "?", "")
Let z = Replace(z, "!", "")
Let z = Replace(z, ";", "")
Let z = Replace(z, ":", "")
Let z = Replace(z, Chr$(34), "") ' Double quote mark

Let Diff = Len(y) - Len(z)

If Diff > 0 Then
SendDragonKeys "{Ctrl+Shift+Left " & Diff & "}"
End If

SendDragonKeys "{Ctrl+i}"
SendDragonKeys "{Right}"
SendDragonKeys "{Ctrl+i}"
End Sub
 03/01/2021 01:25 PM
User is offline View Users Profile Print this message

Author Icon
dinotalking
New Member

Posts: 13
Joined: 02/18/2021

Yes, agreed. Thanks for the script!

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

DPI 15.61.200.010, Sennheiser ME3 Microphone, Lenovo Legion V laptop with 16GB RAM, AMD Ryzen 7 Mobile 4800H Processor (2.9Ghz-4.2Ghz), Realtek (R) Audio 6.0.9003.1. Windows 10 Home 64-bit, Office 2013 Pro.

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

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