Auto bold certain words of pasted text in word processor
Auto bold certain words of pasted text in word processor
Hi all,
I am new to this and I am not even sure what I am looking to do falls within the capabilities of AHK.I am using a version of Dragon Natural Speaking that no longer supports pasting rich text in precanned dictations commands. Now when I issue a dragon command to paste any of my many dictations it will only do so in plain text. I was wondering if it would be possible to have AHK to automatically bold certain words in a pasted text (e.g. "Part 1.", "Part 2","summary"). I am not using MS word but in the word processor I am using ctrl+B still does bold text. Any input would be greatly appreciated, thanks!
I am new to this and I am not even sure what I am looking to do falls within the capabilities of AHK.I am using a version of Dragon Natural Speaking that no longer supports pasting rich text in precanned dictations commands. Now when I issue a dragon command to paste any of my many dictations it will only do so in plain text. I was wondering if it would be possible to have AHK to automatically bold certain words in a pasted text (e.g. "Part 1.", "Part 2","summary"). I am not using MS word but in the word processor I am using ctrl+B still does bold text. Any input would be greatly appreciated, thanks!
-
- Posts: 35
- Joined: 17 Nov 2021, 10:53
Re: Auto bold certain words of pasted text in word processor
Use hotstrings, like this. Just make more for the other strings you desire to auto-bold.
Code: Select all
::Part 1::
Send, Part 1 ; Send text
Sleep, 10 ; sleep to make sure commands register
Send, +{Left 6} ; highlight full word (6 characters)
Sleep, 10
Send, ^b ; Bold the text
Sleep, 10
Send, {Right 6} ; return cursor to original spot
Sleep, 10
Send, ^b ; turn off bold
return
Re: Auto bold certain words of pasted text in word processor
Thank you so much prestonage! I tried out your code and it works great if I manually type out "Part 1" however if Part 1 is pasted from a canned dictation the script isn't activated and thus stays in plain text. I am aware AHK can interpret and can be activated by certain keystrokes not sure if AHK with a key combo can scan words in a active word processor window and apply formatting to these designated words.prestonage wrote: ↑28 Nov 2021, 01:20Use hotstrings, like this. Just make more for the other strings you desire to auto-bold.
Re: Auto bold certain words of pasted text in word processor
This seems close to what I am looking to do but it looks like it will only work on MS word.
https://www.autohotkey.com/board/topic/91284-help-with-script-to-search-for-certain-words-in-a-word-doc-then-center-and-bold/
https://www.autohotkey.com/board/topic/91284-help-with-script-to-search-for-certain-words-in-a-word-doc-then-center-and-bold/
-
- Posts: 35
- Joined: 17 Nov 2021, 10:53
Re: Auto bold certain words of pasted text in word processor
In that case you are way overthinking this. This is a common feature in most word processors. I use libreoffice, and you can do it there.efaustus9 wrote: ↑29 Nov 2021, 00:58This seems close to what I am looking to do but it looks like it will only work on MS word.
https://www.autohotkey.com/board/topic/91284-help-with-script-to-search-for-certain-words-in-a-word-doc-then-center-and-bold/
https://ask.libreoffice.org/t/search-and-replace-to-apply-a-font-attribute/37106
Re: Auto bold certain words of pasted text in word processor
In fact, I think it could be simplified as:
I don't know any word processor that doesn't work these code (changing bold shorcut).
I tested and it didn't work pasting test. It only work when I type manually.
Code: Select all
::Part 1:: Send, ^bPart 1^b
I tested and it didn't work pasting test. It only work when I type manually.
Re: Auto bold certain words of pasted text in word processor
Thanks again unfortunately I have to use a proprietary word processor that's part of a specialized suite and is rather limited. I do have MS word on my machine maybe I could use it as an intermediary. For example possibly a designated ahk sensitive keystroke to open ms word, have it wait 10s for me to deploy canned dictation, next it runs the code I referenced above, than it copies finished formatted text, switches active window and finally pastes output.prestonage wrote: ↑30 Nov 2021, 12:35
In that case you are way overthinking this. This is a common feature in most word processors. I use libreoffice, and you can do it there.
https://ask.libreoffice.org/t/search-and-replace-to-apply-a-font-attribute/37106
-
- Posts: 35
- Joined: 17 Nov 2021, 10:53
Re: Auto bold certain words of pasted text in word processor
I still think you are overthinking the issue. If you have to use this poor-quality word processor for whatever reason, you should be able to just do the adjustments in ms word, and then copy/paste with formatting.efaustus9 wrote: ↑30 Nov 2021, 18:28Thanks again unfortunately I have to use a proprietary word processor that's part of a specialized suite and is rather limited. I do have MS word on my machine maybe I could use it as an intermediary. For example possibly a designated ahk sensitive keystroke to open ms word, have it wait 10s for me to deploy canned dictation, next it runs the code I referenced above, than it copies finished formatted text, switches active window and finally pastes output.prestonage wrote: ↑30 Nov 2021, 12:35
In that case you are way overthinking this. This is a common feature in most word processors. I use libreoffice, and you can do it there.
https://ask.libreoffice.org/t/search-and-replace-to-apply-a-font-attribute/37106
Re: Auto bold certain words of pasted text in word processor
I was able to frankenstein this together from various code I found and it works
I used notepad.exe as the output for testing purposes as I do not have the proprietary company word processing software on my home computer, but you can paste the clipboard back into the word document to confirm the desired formatting.
Code: Select all
#Persistent
^F:: ; ctrl+F initiates script
WinWait ahk_exe WINWORD.EXE
WinActivate ahk_exe WINWORD.EXE
; WinWaitActive ahk_exe WINWORD.EXE
sleep, 5000 ; waits for canned dictation
try ; gards against runtime errors if ComObjActive() failed
oWord := ComObjActive("Word.Application")
catch ; if ComObjActive() failed...
return ; ... stop further execution
oDoc := oWord.documents[1]
oDoc.Select ; makes the Selection object to be the whole document
if (oWord.Selection.Find.Execute("Part .1"))
oWord.Selection.Font.Bold := true
oDoc.Select
if (oWord.Selection.Find.Execute("Part .2"))
oWord.Selection.Font.Bold := true
oDoc.Select
if (oWord.Selection.Find.Execute("Part .3"))
oWord.Selection.Font.Bold := true
oDoc.Select
if (oWord.Selection.Find.Execute("Part .4"))
oWord.Selection.Font.Bold := true
oDoc.Range.FormattedText.Cut ;cuts all formatted text
WinWait ahk_exe notepad.exe
WinActivate ahk_exe notepad.exe
; WinWaitActive ahk_exe notepad.exe
Send ^V ;pastes all formated text
Re: Auto bold certain words of pasted text in word processor
Does this code actually work? more help