Jump to content
Sign in to follow this  
masonj

AutoIT / Notepad Help!

Recommended Posts

masonj

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")

Share this post


Link to post
Share on other sites
evilertoaster

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")

Share this post


Link to post
Share on other sites
masonj

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 :)

Share this post


Link to post
Share on other sites
masonj

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.

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")

Share this post


Link to post
Share on other sites
masonj

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

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.

Share this post


Link to post
Share on other sites
masonj

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

Share this post


Link to post
Share on other sites
HarshChaturvedi

Hi , excuse me if i am being naive but what if we want to create a notepad file and add text to it but all this should happen with the window being in minimized mode?? Is it possible?

Share this post


Link to post
Share on other sites
guinness

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:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Blue_Drache

qzj3uh.jpg


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
DatMCEyeBall

A 8 year old thread hijacker that admits it's for a game at the same time?


"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Share this post


Link to post
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
Sign in to follow this  

×