help me with text creator

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
djowdias97
Posts: 9
Joined: 22 Apr 2021, 16:27

help me with text creator

27 Sep 2021, 14:41

hi, i'm wanting to make a script for example, it takes a list of words from a notepad for example,

house
car
bus

and it adds numbers to the end of each one without repeating for example

house1
car1
bus1

from 1, 0001 to 9999

and saves it again in a new file, would that be possible?

thank you
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: help me with text creator

27 Sep 2021, 14:57

Code: Select all

count := {}, out := "", new := A_ScriptDir "\new.txt"
ControlGetText, text, Edit1, ahk_exe notepad.exe
For each, line in StrSplit(text, "`r`n")
 count[line] := (0 count[line]) + 1, out .= "`n" line count[line]
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"
Last edited by mikeyww on 27 Sep 2021, 15:20, edited 1 time in total.
djowdias97
Posts: 9
Joined: 22 Apr 2021, 16:27

Re: help me with text creator

27 Sep 2021, 15:11

the notepad I wanted to say , is to get the notepad keywords from some way , for example C:\Users\admin\Desktop\here.txt

the script works fine, would it be possible to put it in this form?

house1
house2
house3 <- until 9999
car1
car2
car3 <- until 9999
bus1
bus2
bus3 <- until 9999
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: help me with text creator

27 Sep 2021, 15:42

Code: Select all

word := [], count := {}, out := "", new := A_ScriptDir "\new.txt", max := 9999
ControlGetText, text, Edit1, ahk_exe notepad.exe
For each, item in StrSplit(Trim(text, "`r`n"), "`r`n")
 word.Push(count.HasKey(item) ? "" : item), count[item] := (0 count[item]) + 1
For each, item in word
 Loop, % Min(count[item], max)
  out .= "`n" item A_Index
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"
There's an easier way that someone posted a while back, but I lost track of it.
djowdias97
Posts: 9
Joined: 22 Apr 2021, 16:27

Re: help me with text creator

27 Sep 2021, 15:49

is there a way to choose which file it will take as keywords? I run the file you wrote me and it creates words, but I don't know where it's getting them,
but for the help I'll thank you, you're a beast!
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: help me with text creator

27 Sep 2021, 15:58

Code: Select all

; file = %A_ScriptDir%\words.txt ; Change file path as needed
FileSelectFile, file,,, Select a file, Text documents (*.txt)
If (file = "")
 Return
word := [], count := {}, out := "", new := A_ScriptDir "\new.txt", max := 9999
If !FileExist(file) {
 MsgBox, 48, Error, File not found.`n`n%file%
 Return
} Else FileRead, text, %file%
For each, item in StrSplit(Trim(text, "`r`n"), "`r`n")
 word.Push(count.HasKey(item) ? "" : item), count[item] := (0 count[item]) + 1
For each, item in word
 Loop, % Min(count[item], max)
  out .= "`n" item A_Index
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"
djowdias97
Posts: 9
Joined: 22 Apr 2021, 16:27

Re: help me with text creator

27 Sep 2021, 16:07

mikeyww wrote:
27 Sep 2021, 15:58

Code: Select all

; file = %A_ScriptDir%\words.txt ; Change file path as needed
FileSelectFile, file,,, Select a file, Text documents (*.txt)
If (file = "")
 Return
word := [], count := {}, out := "", new := A_ScriptDir "\new.txt", max := 9999
If !FileExist(file) {
 MsgBox, 48, Error, File not found.`n`n%file%
 Return
} Else FileRead, text, %file%
For each, item in StrSplit(Trim(text, "`r`n"), "`r`n")
 word.Push(count.HasKey(item) ? "" : item), count[item] := (0 count[item]) + 1
For each, item in word
 Loop, % Min(count[item], max)
  out .= "`n" item A_Index
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"
well, now I understand the program but it is not numbered as keywords, for example

house1
house12
house123
house1234
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: help me with text creator

27 Sep 2021, 16:17

It looks like you should step back and provide the exact example that you want, in detail, including both the complete input text and the complete output text. Figure out exactly what you need before you post. The posted script provides output that matches that in your earlier post.
djowdias97
Posts: 9
Joined: 22 Apr 2021, 16:27

Re: help me with text creator

27 Sep 2021, 19:24

mikeyww wrote:
27 Sep 2021, 16:17
It looks like you should step back and provide the exact example that you want, in detail, including both the complete input text and the complete output text. Figure out exactly what you need before you post. The posted script provides output that matches that in your earlier post.
what I need is to load a notepad with some keywords and for each keyword number from 1 to 9999 at the end of the keyword

example

house1
house2
house3
house9999
bike1
bike2
bike3
bike9999
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: help me with text creator

27 Sep 2021, 19:40

That's a real example of the exact output? What was the input? What rules have determined your suffix numbers in your example? In other words, how is the suffix number determined?
djowdias97
Posts: 9
Joined: 22 Apr 2021, 16:27

Re: help me with text creator

27 Sep 2021, 19:59

mikeyww wrote:
27 Sep 2021, 19:40
That's a real example of the exact output? What was the input? What rules have determined your suffix numbers in your example? In other words, how is the suffix number determined?
I simply want any keyword that is in the notepad that I load to be added to the numbers from 1 to 9999 in all the available keywords in the notepad leaving the keyword from 1 to 9999 with no repeats.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: help me with text creator

27 Sep 2021, 20:18

I will just ask for an example a third time: what is an exact input file, and the exact output that you would want for it?
djowdias97
Posts: 9
Joined: 22 Apr 2021, 16:27

Re: help me with text creator

28 Sep 2021, 17:46

I managed to understand the code and it's serving me now, thanks for the help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 348 guests