I use VoiceAttack for everyday computer tasks, and I often find myself repeating commands. Following are some commands I created to make this easier.
In VoiceAttack Options, I set up "rep" as a way to repeat the last command:
Options > Recognition > Repeat Command Phrases: rep
But saying "rep" only allows me to repeat the last command once.
The following command allows me to repeat the last command from 1 to 5 times:
When I say: rep [1..5]
Set integer [~num] value to the converted value of {CMDSEGMENT:1}
COMMENT: The following prevents a subsequent "rep [1..5]" from overwriting the prevCmd variable:
Begin Text Compare : [{PREVIOUSSPOKENCMD}] Does Not Start With 'rep'
Set Text [prevCmd] to '{PREVIOUSSPOKENCMD}'
End Condition
Write '[Blue] prevCmd = {TXT:prevCmd}' to log
Begin Text Compare : [prevCmd] Does Not Equal ''
Start Loop : Repeat [~num] Times
Execute command, '{TXT:prevCmd}' (by name) (and wait until it completes)
End Loop
End Condition
The following two commands allow me to repeat a *series* of commands.
"last [2..5]" captures the last 2 to 5 commands that were spoken, and then runs the command "last rep".
"last rep" executes the commands captured by "last [2..5]".
When I say: last [2..5]
Set integer [~num] value to the converted value of {CMDSEGMENT:1}
Set integer [lastNum] value to the converted value of {CMDSEGMENT:1}
Start Loop : Repeat [~num] Times
Begin Text Compare : [{SPOKENCMD:{INT:~num}}] Starts With 'rep'
Write '[Red] Repeating the custom command "rep [1..5]" is not allowed! It creates endless loops!' to log
Exit Command
End Condition
Set Text [lastCmd({INT:~num})] to '{SPOKENCMD:{INT:~num}}'
Set integer [~num] to [~num] minus 1
End Loop
Execute command, 'last rep' (by name) (and wait until it completes)
When I say: last rep
Set integer [~num] value to the value of [lastNum]
Set integer [~cmdNum] value to the value of [lastNum]
Start Loop : Repeat [~num] Times
Write '[Blue] lastCmd({INT:~cmdNum}) = {TXT:lastCmd({INT:~cmdNum})}' to log
Execute command, '{TXT:lastCmd({INT:~cmdNum})}' (by name) (and wait until it completes)
Set integer [~cmdNum] to [~cmdNum] minus 1
End Loop
I have attached a VoiceAttack profile containing these commands.
Note: These commands use the following global variables:
prevCmd
lastNum
lastCmd(1) .. lastCmd(5)
Please make sure they don't conflict with global variables used by your own commands.
I hope others find these commands as helpful as I do. Feedback and suggestions are welcome.