rorororo Posted June 26, 2010 Posted June 26, 2010 I just started learning AutoIt and love it so far. However, I'm not exactly sure how to create a script that would do the following. I was wondering if someone could write a simple AutoIt script that would open a text document (let's call it milk.txt) and also open another notepad (Untitled - Notepad) then write everything from milk.txt to the new, untitled document. It should press enter whenever there is a new line. I don't want it to just copy and paste since that wouldn't really work with what I plan on changing the script into. It needs to actually read each letter from milk.txt and send that keystroke to the new document. Any help would be greatly appreciated, thanks.
somdcomputerguy Posted June 26, 2010 Posted June 26, 2010 How about a simple use of the FileCopy (http://www.autoitscript.com/autoit3/docs/functions/FileCopy.htm) function? - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
rorororo Posted June 26, 2010 Author Posted June 26, 2010 How about a simple use of the FileCopy (http://www.autoitscript.com/autoit3/docs/functions/FileCopy.htm) function?I didn't know about that before so thank you for showing me it. However, I was using copying from one text document to another as an example. I actually want to be able to read text from a text document and type it into any other window, whether it be Firefox, AIM, etc. Sorry for not just saying that in the original post. I wanted to get an example script from someone else then be able to edit it to my own liking in order to get the hang of scripting with AutoIt.
somdcomputerguy Posted June 26, 2010 Posted June 26, 2010 Look at any of File functions in the Help file, and also the Send and ControlSend functions. The links in my sig are helpful and/or contain links to other helpfulsome things.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
ichigo325 Posted June 26, 2010 Posted June 26, 2010 Here some simple example : $hFile = FileOpen(".\milk.txt",0) Run("notepad.exe") WinWaitActive("Untitled - Notepad") ControlSetText("[CLASS:Notepad]","","Edit1",FileRead($hFile)) FileClose($hFile) [size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size]
Inconspicuous Posted June 26, 2010 Posted June 26, 2010 Here's an example where each character from milk.txt is sent to a new notepad with a keystroke. I would use the example in the previous post, it's more efficient. dim $sendChar dim $readFile = ".\milk.txt" dim $dataInfo = FileRead($readfile) dim $dataCount = @extended dim $dataArray = StringSplit($dataInfo, "", 0) Run("notepad.exe") WinWaitActive("Untitled - Notepad") For $x=1 To $dataCount Step 1 $sendChar = $dataArray[$x] ControlSend("[CLASS:Notepad]", "", "Edit1", $sendChar) Next Exit
Confuzzled Posted June 26, 2010 Posted June 26, 2010 I just started learning AutoIt and love it so far. However, I'm not exactly sure how to create a script that would do the following. I was wondering if someone could write a simple AutoIt script that would open a text document (let's call it milk.txt) and also open another notepad (Untitled - Notepad) then write everything from milk.txt to the new, untitled document. It should press enter whenever there is a new line. I don't want it to just copy and paste since that wouldn't really work with what I plan on changing the script into. It needs to actually read each letter from milk.txt and send that keystroke to the new document. Any help would be greatly appreciated, thanks. You'll need to read the help file as I'm only giving you pseudo code and you will have to turn it into AutoIT: Open up milk.txt in input mode Open up notepad.exe Do the following until end of file is reached Read a line from the input file Write it to the notepad screen Write a end-of-line @CRLF to the notepad screen Loop until the end of file is reached Close the input file Do whatever you want to in the notepad screen This is a simple exercise that is taught early on in programming classes. It involves loops, file manipulation, and string manipulation. You will probably find the autoit 123 tutorial of significant assistance also. I suggest you spend some time there and then return with any remaining questions.
rorororo Posted June 26, 2010 Author Posted June 26, 2010 Thank you all very much for the replies! It was only three lines. I am very impressed with how great this language is.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now