Jump to content

Recommended Posts

Posted

Noob here...

Ive been playing around a little with the notepad example from AutoIT. So far I can get it to open a file, write some text to it, and then do a Save As. The code I have for this is below, and it seems to work.

The problem I am having is that I need to do something where I provide the path, like in the following:

Send("myFile\shortFile.pc0")

But this doesnt work unless notepad happens to open in myFile.

It seems to me that I need to gain control over the Look in (combobox?) field so that "myFile\outFile1" will make sense to it, but so far no luck. Im out of ideas, so any help would be greatly appreciated.

;Run Notepad
Run("notepad.exe")

;Wait for the Notepad become active
WinWaitActive("Untitled - Notepad")

;slow things down so I can see what's happening
AutoItSetOption("SendKeyDelay", 200)

;get ready to open a file
WinMenuSelectItem("Untitled - Notepad", "", "&File", "&Open" )

;the name of the file to open is "shortFile.pc0".
;the .pc0 is just a text file on the inside.    
;ControlSend("Open", "", "Edit1", "myFile\shortFile.pc0");doesnt work??
Send("myFile\shortFile.pc0");this works as long as notepad opens to myFile

;click the Open button
Send("!o")

;write some text
;Send("This is some text.")

;get ready to save the file. 
;Note that the name of the window is now "shortFile.pc0"
WinMenuSelectItem("shortFile.pc0", "", "&File", "Save &As..." )

;set the name of the file to save to "outFile"
ControlSend("Save As", "", "Edit1", "outFile1")

;save it as a text file
;ControlSend("Save As", "", "ComboBox3", "Text File (*.txt)")
ControlSend("Save As", "", "ComboBox3", "All Files")

;click the "Save" button
Send("!s")

;close notepad
;WinClose("outFile.txt - Notepad")
Send("!f")
Send("x")
Posted

  evilertoaster said:

It would be possible to script the GUI as you are trying to do, but it would be much simpler to just do somthing like-

Run("notepad.exe C:\folder\myFile\shortFile.pc0")
evilertoaster:

That works for me! And how simple I had no idea notepad could start like that. Thanks very much!

Mason :)

Posted

Does anyone know how I can specify the folder that I open from and/or save to? Should I be trying to set the look in combobox? If so, how do you do that?

This morning it dawned on me that not all applications are going to take the extra argument (as suggested by evilertoaster) the way that notepad does.

  masonj said:

Noob here...

Ive been playing around a little with the notepad example from AutoIT. So far I can get it to open a file, write some text to it, and then do a Save As. The code I have for this is below, and it seems to work.

The problem I am having is that I need to do something where I provide the path, like in the following:

Send("myFile\shortFile.pc0")

But this doesnt work unless notepad happens to open in myFile.

It seems to me that I need to gain control over the Look in (combobox?) field so that "myFile\outFile1" will make sense to it, but so far no luck. Im out of ideas, so any help would be greatly appreciated.

;Run Notepad
Run("notepad.exe")

;Wait for the Notepad become active
WinWaitActive("Untitled - Notepad")

;slow things down so I can see what's happening
AutoItSetOption("SendKeyDelay", 200)

;get ready to open a file
WinMenuSelectItem("Untitled - Notepad", "", "&File", "&Open" )

;the name of the file to open is "shortFile.pc0".
;the .pc0 is just a text file on the inside.    
;ControlSend("Open", "", "Edit1", "myFile\shortFile.pc0");doesnt work??
Send("myFile\shortFile.pc0");this works as long as notepad opens to myFile

;click the Open button
Send("!o")

;write some text
;Send("This is some text.")

;get ready to save the file. 
;Note that the name of the window is now "shortFile.pc0"
WinMenuSelectItem("shortFile.pc0", "", "&File", "Save &As..." )

;set the name of the file to save to "outFile"
ControlSend("Save As", "", "Edit1", "outFile1")

;save it as a text file
;ControlSend("Save As", "", "ComboBox3", "Text File (*.txt)")
ControlSend("Save As", "", "ComboBox3", "All Files")

;click the "Save" button
Send("!s")

;close notepad
;WinClose("outFile.txt - Notepad")
Send("!f")
Send("x")
Posted

It seems to me that this should work:

Run("notepad.exe")

;Wait for the Notepad become active
WinWaitActive("Untitled - Notepad")
;slow things down so I can see what's happening
AutoItSetOption("SendKeyDelay", 100)
;get ready to open a file
WinMenuSelectItem("Untitled - Notepad", "", "&File", "&Open" )

Send("!i");Look &in:
Send("C:\EasyScan\myFile")

But it doesn't. Surely someone out there must know the answer. This has got to be basic AutoIT stuff isn't it?!

Mason

  masonj said:

Does anyone know how I can specify the folder that I open from and/or save to? Should I be trying to set the look in combobox? If so, how do you do that?

This morning it dawned on me that not all applications are going to take the extra argument (as suggested by evilertoaster) the way that notepad does.

Posted

  Volly said:

Are you simply trying to put text into a file? You can use filewrite to do it.

No, I'm trying to control the directory that I read and write from by using the "Look in" drop down box that's displayed when you try to Open or Save As.

post-36091-1212174947_thumb.jpg

  • 5 years later...
Posted

This is an old thread, so please don't revive in the future.

Why do you want to use notepad when AutoIt can directly interact with files?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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