Jump to content

Trying to learn AutoIt and appreciate help making this script.


Recommended Posts

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...