Jump to content
Sign in to follow this  

Open text file wirh Notepad and wait until text file is saved

Recommended Posts



i start with new script to ad computer names to empty text file. The steps to do this are: Press Button "New CP Name List". Script check if cpnamelist.txt exist and delete it. Script create a new one. Now Script open cpnamelist.txt with notepad and i paste computer names in to this file and save file. How can i stop script until content is saved. I have tried Miscellaneous (winwait etc.) but somthing was wrong.


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("CP Name List", 615, 438, 522, 356)
$ListCPNameList = GUICtrlCreateList("", 25, 25, 96, 383)
$ButtonNewCPNameList = GUICtrlCreateButton("New CP Name List", 130, 120, 105, 25)
$ButtonAddCPName = GUICtrlCreateButton("Add CP Name", 130, 30, 105, 25)
$ButtonRemoveCPName = GUICtrlCreateButton("Remove CP Name", 130, 60, 105, 25)
$InputCPName = GUICtrlCreateInput("", 245, 30, 121, 21)

 While 1
    $msg = GUIGetMsg()
        ;Case $GUI_EVENT_CLOSE
             Case $msg = $GUI_EVENT_CLOSE

            Case $msg = $ButtonNewCPNameList
            MsgBox(0, "Note", "$ButtonNewCPNameList")


            If FileExists($CPnameList) Then FileDelete($CPnameList) ; CPNameList if exist.

            $hFile = FileOpen("D:\AutoIT_Scripts\writefile\temp\cpnamelist.txt", 1)

            $sText = FileRead("D:\AutoIT_Scripts\writefile\temp\cpnamelist.txt", 1)
            $sText = StringReplace($sText, @CRLF, '|')
            $sText = StringReplace($sText, '||', '|')
            GUICtrlSetData($ListCPNameList, $sText)

            Case $msg = $ButtonAddCPName
            MsgBox(0, "Note", "$ButtonAddCPName")

            Case $msg = $ButtonRemoveCPName
            MsgBox(0, "Note", "$ButtonRemoveCPName")


 func terminate()                                                                     ;exit
    Exit 0


Share this post

Link to post
Share on other sites

Your script doesn't use Notepad in it.

You need to add a FileWrite to write the data to the file, which is also missing in your script.

Don't use Notepad to do this, it just adds complexity to a simple process.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

  • Similar Content

    • SkysLastChance
      By SkysLastChance
      Run("notepad.exe") GLOBAL $One = ('Line1' & _ 'Line2' & _ 'Line3' & _ 'Line4' & _ 'Line5') ClipPut($One) $Notepad = WinWait("[CLASS:Notepad]", "", 10) ControlSend("Untitled - Notepad", "", "", ("^v")) Instead of having this paste as Line1Line2Line3Line4Line5
      How can I make it paste it into notepad as (without double spacing.)
    • Skeletor
      By Skeletor
      Hi Guys,
      When I used to scratch the surface with Delphi5, I could only create a simple Notepad program.
      Now that I'm into AutoIt, I've created just a bare bone Notepad.
      Can be improved, but maybe this will be useful for those, like me, starting out with programming.
      I know there are way better notepads out there like Aupad, but,
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <APIDlgConstants.au3> #include <Memory.au3> #include <WinAPIDlg.au3> #include <WinAPIFiles.au3> Opt('WinTitleMatchMode', 3) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Notepad", 620, 440, 192, 124) $MenuItem1 = GUICtrlCreateMenu("File") $MenuItem4 = GUICtrlCreateMenuItem("New" & @TAB & "Ctrl+N", $MenuItem1) $MenuItem5 = GUICtrlCreateMenuItem("Open" & @TAB & "Ctrl+O", $MenuItem1) $MenuItem6 = GUICtrlCreateMenuItem("Save" & @TAB & "Ctrl+S", $MenuItem1) $MenuItem17 = GUICtrlCreateMenuItem("Print" & @TAB & "Ctrl+P", $MenuItem1) $MenuItem7 = GUICtrlCreateMenuItem("Exit" & @TAB & "Ctrl+W", $MenuItem1) $MenuItem2 = GUICtrlCreateMenu("Edit") $MenuItem8 = GUICtrlCreateMenuItem("Undo" & @TAB & "Ctrl+Z", $MenuItem2) $MenuItem9 = GUICtrlCreateMenuItem("Cut" & @TAB & "Ctrl+X", $MenuItem2) $MenuItem10 = GUICtrlCreateMenuItem("Copy" & @TAB & "Ctrl+C", $MenuItem2) $MenuItem11 = GUICtrlCreateMenuItem("Paste" & @TAB & "Ctrl+V", $MenuItem2) $MenuItem12 = GUICtrlCreateMenuItem("Delete" & @TAB & "Del", $MenuItem2) $MenuItem16 = GUICtrlCreateMenu("Format") $MenuItem19 = GUICtrlCreateMenuItem("Word Wrap", $MenuItem16) $MenuItem18 = GUICtrlCreateMenuItem("Font", $MenuItem16) $MenuItem15 = GUICtrlCreateMenu("View") $MenuItem20 = GUICtrlCreateMenuItem("Status Bar", $MenuItem15) $MenuItem3 = GUICtrlCreateMenu("Help") $MenuItem13 = GUICtrlCreateMenuItem("View Help", $MenuItem3) $MenuItem14 = GUICtrlCreateMenuItem("About Notepad" & @TAB & "F1", $MenuItem3) $Edit1 = GUICtrlCreateEdit("", 0, 0, 620, 420, $ES_WANTRETURN) GUICtrlSetFont($Edit1, 10, 400, -1, "Lucida Console") GUICtrlSetData(-1, "") Dim $Form1_AccelTable[11][2] = [["^n", $MenuItem4], ["^o", $MenuItem5], ["^s", $MenuItem6], ["^p", $MenuItem17], ["^w", $MenuItem7], ["^z", $MenuItem8], ["^x", $MenuItem9], ["^c", $MenuItem10], ["^v", $MenuItem11], ["{DEL}", $MenuItem12], ["{F1}", $MenuItem14]] GUISetAccelerators($Form1_AccelTable) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Warning If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(52, "Notepad Closing", "Are you sure you want to exit?") Select Case $iMsgBoxAnswer = 6 ;Yes Exit Case $iMsgBoxAnswer = 7 ;No EndSelect #EndRegion --- CodeWizard generated code Start --- Case $MenuItem4 GUICtrlSetData($Edit1, "") Case $MenuItem5 FileOpenDialog("Open Text File", @DesktopDir, "Text File (*.txt)") Case $MenuItem6 $filesave = FileSaveDialog("Save Text File", @DesktopDir, "Text File (*.txt)") $Edit1_Read = GUICtrlRead($Edit1) FileWrite($filesave, $Edit1_Read) Case $MenuItem7 #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Warning If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(52, "Notepad Closing", "Are you sure you want to exit?") Select Case $iMsgBoxAnswer = 6 ;Yes Exit Case $iMsgBoxAnswer = 7 ;No EndSelect #EndRegion --- CodeWizard generated code Start --- EndSwitch WEnd If you don't attempt something, you never know you can actually achieve that goal.
    • chacoya121
      By chacoya121
      plz help how to organize information from notepad or INIfile
      0=000308 1=000308 2=000308 3=000308 4=000408 5=000408 6=000408 7=000408 8=000408 9=000408 10=000308 11=000308 12=000308 13=000408 14=000408 15=000408 16=000408 17=000408 18=000408 19=000408 20=000308 21=000308 22=000308 23=000408 24=000408 25=000408 26=000408 27=000408 28=000408 29=000408 30=000308  0=000308 x 11 total
       1=000408 x 20 total
      2 lines summary all
      Thank you
    • dreivilo47
      By dreivilo47
      I have a Dutch version of Windows 10.
      The Dutch word for "File" = "Bestand" and for "Page Setup" = "Pagina-instelling".
      WinMenuSelectItem doesn't select this items.  What can be the reason?
      Run("notepad.exe") WinWaitActive("[CLASS:Notepad]") WinMenuSelectItem("[CLASS:Notepad]", "", "Bestand", "Pagina-instelling...") Sleep(4000) WinClose("[CLASS:Notepad]")  
    • PINTO1927
      By PINTO1927
      Hi guys,
      you can know the @namecomputer or ip address of the client who opened a notepad file?
      I created a chat through a shared notepad .. and I thought of adding an edit "who is online" ..
      here it is the code: 
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #include <GuiButton.au3> #include <TrayConstants.au3> #include <Color.au3> #include <ColorConstants.au3> #include <ButtonConstants.au3> #include <GUIComboBox.au3> #Include <GuiComboBoxEx.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> #include <GuiEdit.au3> #include <Array.au3> #include <Misc.au3> #include <ColorConstantS.au3> Local $hDLL = DllOpen("user32.dll") FileInstall("C:\birra.ico",@TempDir & "\birra.ico") GUISetIcon(@TempDir & "\birra.ico", -1) Global $sFileToCheck = "\\\cond\chat.txt" Global $bFileChanged = False Global $sFileDateTime = _ArrayToString(FileGetTime($sFileToCheck)) AdlibRegister("_CheckFile", 250) $FormComunicazioni = GUICreate("NAME CHAT", 450, 500, -1, -1) GUISetBkColor($COLOR_BLACK) GUISetFont(11, 400, 0, "Calibri") $EditComunicazioni = GUICtrlCreateEdit("",20, 20, 410, 350, BitOR($ES_READONLY, $CBS_AUTOHSCROLL, $WS_VSCROLL)) GUICtrlSetData(-1, "- Chat" & " " & @MDAY & "\" & @MON & "\" & @YEAR) $AggiornaComunicazioni = GUICtrlCreateButton("recupera conversazione iniziale", 20, 385, 200, 30) $edit = GUICtrlCreateEdit("", 20, 430, 340, 55, BitOR($CBS_AUTOHSCROLL, $WS_VSCROLL)) $invia = GUICtrlCreateButton("Invia", 365, 428, 67, 58) GUISetState(@SW_SHOW) While 1 Sleep(10) If $bFileChanged Then $file= FileOpen ("\\\cond\chat.txt",0) $last_line = FileReadLine ($file, -1) _GUICtrlEdit_AppendText($EditComunicazioni, @CRLF & $last_line) FileClose($file) $sFileDateTime = _ArrayToString(FileGetTime($sFileToCheck)) $bFileChanged = False TrayTip("Stranguglie e previdi", "è presente un nuovo messaggio", 0, $TIP_ICONASTERISK) GUISetState(@SW_RESTORE) EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $invia ClipPut(GUICtrlRead($edit)) FileWrite("\\\cond\chat.txt", @CRLF & "[" & @UserName & "]" & " scrive: " & ClipGet()) Sleep(100) Guictrlsetdata($edit,"") Case $AggiornaComunicazioni $file = FileOpen("\\\cond\chat.txt", 0) $FileContent = FileRead($file) _GUICtrlEdit_AppendText($EditComunicazioni, @CRLF & @CRLF & $FileContent) FileClose($file) GUICtrlSetState($AggiornaComunicazioni, $GUI_DISABLE) EndSwitch WEnd DllClose($hDLL) Func _CheckFile() If $sFileDateTime <> _ArrayToString(FileGetTime($sFileToCheck)) Then $bFileChanged = True EndFunc