Add bullet numbers

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tnmc77
Posts: 18
Joined: 27 Aug 2017, 16:53

Add bullet numbers

24 Sep 2017, 15:58

I want to add number bullets to sequential lines in the microsoft word like program as follows...

Line one.
Line Two.
Line three.
Line four.

is converted to

1. Line one.
2. Line Two.
3. Line three.
4. Line four.

I should be able to keep the script running and do this again and again on different files one after another.

Thanks.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Add bullet numbers

24 Sep 2017, 18:48

Hi tnmc77,

Code: Select all

; CONCLUSION:
; abc
; def
; ghi

F11::
Send ^a^c
ClipWait
str := "" ; an empty string
Loop, Parse, % Trim(clipboard, "`r`n"), `n, `r ; retrieves substrings (fields) from the clipboard, one at a time, using the linefeed as delimiter
	str .= (a_index-1) . ". " . A_LoopField . "`r`n" ; appends the number minus 1 of the current loop iteration, a dot, the field and a linefeed-carriage return to the string
SendInput % LTrim(str, "0. ") ; sends the string omitting "0. " from the beginning
return ; end of the subroutine

; -------------------------

; abc
; def
; ghi

F12::
Send ^a^c
ClipWait
str := ""
Loop, Parse, % Trim(clipboard, "`r`n"), `n, `r
	str .= a_index . ". " . A_LoopField . "`r`n"
SendInput % str
return

my scripts
tnmc77
Posts: 18
Joined: 27 Aug 2017, 16:53

Re: Add bullet numbers

24 Sep 2017, 19:02

A_Ahkuser,
Many many thanks.
The F12 script, not only numbers selected items but also lines in the rest of the page.
F11 script also numbers Conclusion line and not the lines which follow it. Also, it seems to change spacing and indent.
Thanks.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Add bullet numbers

24 Sep 2017, 19:21

If you want to prevent the script from number all the item and modify the selected items instead, substitute this line:

Code: Select all

Send ^a^c ; sends CTRL+A CTRL+C
by this other one:

Code: Select all

Send ^c ;  ; sends CTRL+C
I doubt the script change the spacing and indent: actually, there's no space nor tab in the script. If you talk about interlining, you can try instead of:

Code: Select all

A_LoopField . "`r`n"
this variant:

Code: Select all

A_LoopField . "`n"
my scripts
tnmc77
Posts: 18
Joined: 27 Aug 2017, 16:53

Re: Add bullet numbers

24 Sep 2017, 19:26

I cant believe I did not see the flaw of ^a^c. I just tried. Works like a charm. Many thanks. You rock.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Add bullet numbers

24 Sep 2017, 19:31

Btw I should empty the clipboard before clipwait - i.e.:

Code: Select all

F12::
clipboard =
Send ^c
ClipWait
; ...
my scripts
tnmc77
Posts: 18
Joined: 27 Aug 2017, 16:53

Re: Add bullet numbers

24 Sep 2017, 19:39

Thank you much
tnmc77
Posts: 18
Joined: 27 Aug 2017, 16:53

Re: Add bullet numbers

25 Sep 2017, 07:51

At work and the F12 script is working awesome. One issue...if there is a solution for it. (I am using Powerscribe, which is windows based - similar key commands as word).

It is adding space between lines. Any solution?
Many thanks.

Line one.
Line Two.
Line three.
Line four.

is converted to

1. Line one.

2. Line Two.

3. Line three.

4. Line four.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Add bullet numbers

26 Sep 2017, 12:40

OK my bad; I missed the fact that you're working on word: actually, i tested it in notepad and now I can understand how spaces and tabs appear. I don't have word so I can't test it but it seems to me that Word works just like Open Office and recognize a pattern and convert the input into a ordered list. One solution could be to substitute the dot with another symbol in order to thwart the pattern recognition. For example, using the median dot (UTF-32BE n°188):

Code: Select all

str .= a_index . Chr(183) . A_Space . A_LoopField . "`r`n"
Concerning the interlining did you try the alternative that I suggested you in my answer above ? - i.e.:

Code: Select all

A_LoopField . "`n"
Hope this helps
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 365 guests