Insert text
I've spent about two hours now looking for some simple explanations of how to automate sending a line of text to a notepad++ file.
I've made my way through the command list, and have searched for sample scripts that promise to modify text files, insert text, and so forth. I've had no success, and am wondering why the solution is so opaque.
Send doesn't do it
ControlSend doesn't do it
FileAppend doesn't do it.
InputBox requires me to retype the line of text every time, which is exactly what I want to avoid.
For example, if I go to the Control Send command description, it says
ControlSend, Edit1, This is a line of text in the notepad window., Untitled
but if I paste that into a new.ahk file, save it and press F5, nothing happens.
If I add #q:: to the start of the line, save & minimise that window, and run it, nothing happens.
Same for each of the other commands.
So, how does one send a line of text to a file? Why isn't it made obvious someplace easy to find?
Can someone point me to an explanation, or even a sample script?
Y'all want to append text to a file?
#t:: ;Windows t actionlist = C:\Users\my.name\Documents\Personal\action.txt InputBox, myinputbox,Action,Current,,500,120,400,300 FormatTime, TimeString, %calendar%, h:mm:ss tt ;non-US dates mytime = %A_DD%/%A_MM%/%A_YYYY% %TimeString% FileAppend, %mytime% %myinputbox%`n,%actionlist% return
I want to open an instance of a text editor (notepad, notepad++, whatever), and add some text to it, for example:
Hello World,
this is a line of text.
I want to insert those same two lines with one keystroke, i.e. #t, in whatever file is open, most likely a new, un-named file.
For example, something like this seems like it should work:
#t:: run, notepad.exe FileAppend, Hello World `n FileAppend, This is a line of text. `n returnBut it doesn't.
Any suggestions?
#t:: run, notepad.exe ; OK FileAppend, Hello World `n ; FileAppend CREATES or APPENDS to a FILE it is NOT used to write to a window FileAppend, This is a line of text. `n ; AND your filename is missing as well so nothing is created return
You need
SetTitleMatchmode, 2 ; partial title match #t:: run, notepad.exe ; OK WinWait, Notepad WinActivate, Notepad Send, Hello World `n Send, This is a line of text. `n Return
or with any window that has focus:
#t:: Send, Hello World `n Send, This is a line of text. `n Return
Getting somewhere now.
SetTitleMatchmode, 2 ; partial title match #t:: run, notepad.exe ; OK WinWait, Notepad WinActivate, Notepad Send, Hello World `n Send, This is a line of text. `n Return
So,
a) Send is the appropriate command; That's not been clear so far, and I've been trying all those other commands unnecessarily...
I need to specify a filename; again, none of the examples I've seen said so in their explanations. It's not intuitively obvious.
c) SetTitleMatchmode or a focused window is required for the script to locate the file.
d) I should use WinWait and WinActivate instead of Sleep; I'd been trying that while notepad opened.
With that sorted, here's something closer to what I want:
SetTitleMatchmode, 2 ; partial title match #k:: ; Windows+k run, notepad++.exe ; run Notepad++ WinWait, Notepad++ ; wait for it WinActivate, Notepad++ ; focus it Send, <NameBlock>`n ; first line send, <category id=`" ; beginning of second line, up to the open quote mark InputBox, UserInput, Category Name ; fill in value between quotes send, `">`n ; close quote <color>#000000</color> ; color the text send, </category>`n ; close category tag
What I want out is:
<NameBlock>
<category id="Name">
<color>#000000</color>
</category>
What I get is:
<NameBlock>
<category id=""> ; Name is missing
<color>000000</color> ; # is missing
<description></description>
</category>
So, that's major progress just getting the lines inserted (for which, thanks!), but now having trouble
a) why isn't the InputBlock working?
how do I specify the hash key in the color tag?
Fab!
Getting somewhere now.SetTitleMatchmode, 2 ; partial title match #t:: run, notepad.exe ; OK WinWait, Notepad WinActivate, Notepad Send, Hello World `n Send, This is a line of text. `n Return
So,
a) Send is the appropriate command; That's not been clear so far, and I've been trying all those other commands unnecessarily...
I need to specify a filename; again, none of the examples I've seen said so in their explanations. It's not intuitively obvious.
c) SetTitleMatchmode or a focused window is required for the script to locate the file.
d) I should use WinWait and WinActivate instead of Sleep; I'd been trying that while notepad opened.
With that sorted, here's something closer to what I want:SetTitleMatchmode, 2 ; partial title match #k:: ; Windows+k run, notepad++.exe ; run Notepad++ WinWait, Notepad++ ; wait for it WinActivate, Notepad++ ; focus it Send, <NameBlock>`n ; first line send, <category id=`" ; beginning of second line, up to the open quote mark InputBox, UserInput, Category Name ; fill in value between quotes send, `">`n ; close quote <color>#000000</color> ; color the text send, </category>`n ; close category tag
What I want out is:
<NameBlock>
<category id="Name">
<color>#000000</color>
</category>
What I get is:
<NameBlock>
<category id=""> ; Name is missing, even though the InputBox prompt does run
<color>000000</color> ; # is missing
<description></description>
</category>
So, that's major progress just getting the lines inserted (for which, thanks!), but now having trouble
a) why isn't the InputBlock working?
how do I specify the hash key in the color tag?
SetTitleMatchmode, 2 ; partial title match #k:: ; Windows+k run, notepad++.exe ; run Notepad++ WinWait, Notepad++ ; wait for it WinActivate, Notepad++ ; focus it InputBox, [color=red]UserInput[/color], Category Name ; fill in value between quotes Send, <NameBlock>`n ; first line send, <category id=`"[color=red]%UserInput%[/color]`">`n ; close quote Send, <color>[color=red]`#[/color]000000</color> ; color the text #!^+ are "special" keys see key names http://www.autohotkey.com/docs/commands/Send.htm so you can also use Send {#} send, </category>`n ; close category tag
The code above is not the most efficient but should get you started.
Start with the tutorials (regular and the one for noobs in my sig)
It is all there in the documentation if you read the correct page that is :wink:
The code above is not the most efficient but should get you started.
Start with the tutorials (regular and the one for noobs in my sig)
Thanks for the UserInput shortcut - very handy!
The hashtag escape doesn't work.
I'd tried it a couple of ways, and even using your sample verbatim still strips it out of the result.
So it's the bracketed version for me...
I've been reading tutorials, sample, and whatnot til I'm red/blue/cross-eyed, which is why I resorted to the forum - which is obviously where I should have gone first!
One further question:
the ultimate aim is to pull category names from a spreadsheet column, insert them in two places as tags, and save the result as an XML file with the same category name.
Do you know of anything similar that I can play with?
<!-- m -->http://www.autohotke...c31923-135.html<!-- m -->
Note that you could use a CSV file which you can read and parse in AutoHotkey.
If by spreadsheet you mean Excel:
<!-- m -->http://www.autohotke...c31923-135.html<!-- m -->
Note that you could use a CSV file which you can read and parse in AutoHotkey.
Either is fine with me - though I suspect going the CSV route would be easier.
If I've got a list of 200 categories and want an XML file for each, it doesn't matter what format the list is in, so long as I can pull each one in individually.
It's clear that I need to get to some point higher on the learning curve to make sense of that.
This seems to be based on specialised mini-routines like CSV_Load, CSV_Read and so on. Since I am still struggling to understand the basic syntax, these more sophisticated forms seem like they require some more involved concepts.
in the background
setBatchLines, 1 run, notepad,,, npPid winWait, % npPid := "ahk_pid " npPid i:=!i loop { random, nM, 0x41, 0x7A controlSend, edit1, % ( ( i<0x1E ) ? chr( nM ) subStr( i++, 1, 0 ) : chr( 0xA ) subStr( i:=!i, 1, 0 ) ) , % npPid } esc::Exitapp ; <- press escape to exitI call this GhostInTheNotepad () :lol:..
htms
don't duplicate, iterate!
What i want to do is just have it paste text(so i dont have to copy and paste) i dont really want it to open notepad and have it type it i just want to be able to go into a text box and the the hot key and it pastes in the text box.
Sorry did not want to create post so i will use this.
Is there any chance to set variable to any symbol in autohotkey?
I want to make a script that would open file , go through test searching for specific format. For example
searchingtext = "anysymbols - anysymbols - anysymbols"
i want to keep dashes in variable but in between them can be any 3 or 4 symbols.
Is it even possible in autohotkey?