arnabg Posted December 18, 2012 Share Posted December 18, 2012 I am having this script but it is not working. modified notepads not being saved ... nor untitled notepads being saved. Local $var = WinList() ; proceed through all windows… For $i = 1 To $var[0][0] If $var[$i][0] "" Then ; if " – Notepad" in window title… If StringInStr($var[$i][0]," - Notepad") 0 Then MsgBox(0,"Msg",$var[$i][0]) If (StringCompare ( $var[$i][0],"Untitled – Notepad") 0) Then ; send CTRL-s to Edit control in window. ControlSend($var[$i][0], "", "[CLASS:Edit;INSTANCE:1]", "^s") EndIf EndIf EndIf Next Pls let me know correct script for saving all notepads which are open (maximized and minimized both). Thanks in advance for your help Link to comment Share on other sites More sharing options...
Thatusernameisalreadytaken Posted December 18, 2012 Share Posted December 18, 2012 The script is correct except for <>s missing in each of IF statements. However, if you just send Ctrl+S, in some cases a save dialog will appear instead of saving Local $var = WinList() ; proceed through all windows… For $i = 1 To $var[0][0] If $var[$i][0]<>"" Then ; if " – Notepad" in window title… If StringInStr($var[$i][0]," - Notepad")<>0 Then MsgBox(0,"Msg",$var[$i][0]) If (StringCompare ($var[$i][0],"Untitled – Notepad")<>0) Then ; send CTRL-s to Edit control in window. ControlSend($var[$i][0], "", "[CLASS:Edit;INSTANCE:1]", "^s") EndIf EndIf EndIf Next Link to comment Share on other sites More sharing options...
JohnOne Posted December 18, 2012 Share Posted December 18, 2012 First, only list notepad windows. $aNotepad = WinList("[Class:Notepad]") AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
arnabg Posted December 19, 2012 Author Share Posted December 19, 2012 @ThatusernameisalreadytakenI tried your correction but it is not actually saving any notepad which is minimized. Only maximized notepads are being saved. Can you pls check and let me know how to save all notepads (both minimized & maximized) after every 5 minutes. Pls show me the changes. Thanks in advance and thanks for reply@JohnoneI am new in this, Can you pls show the full script with $aNotepad. That will be great help. I want to save all notepads (both minimized & maximized) after every 5 minutes. Pls show me the changes. Thanks for reply Link to comment Share on other sites More sharing options...
BrewManNH Posted December 19, 2012 Share Posted December 19, 2012 You're not going to be able to autosave any notepad documents that haven't already been created. No matter what you try you're going to get a dialog box asking you for a file name if the document is new. Also, JohnOne's example shows you how to get ONLY the Notepad windows so you never have to check whether the winlist return contains the name notepad in it, just save the contents of every window returned, because they're all Notepad windows. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
arnabg Posted December 20, 2012 Author Share Posted December 20, 2012 You're not going to be able to autosave any notepad documents that haven't already been created. No matter what you try you're going to get a dialog box asking you for a file name if the document is new.Also, JohnOne's example shows you how to get ONLY the Notepad windows so you never have to check whether the winlist return contains the name notepad in it, just save the contents of every window returned, because they're all Notepad windows.I am Ok with that. My problem is ... with this code ... I can't saved minimized notepads ... only maximized notepads being saved. Pls show me what code will also save minimized notepadsI saw JohnOne's example but being a new to this ... I requested for code example ... so that I can understand easilyHope things are clear now. Pls help! Thanks in advance Link to comment Share on other sites More sharing options...
BrewManNH Posted December 20, 2012 Share Posted December 20, 2012 From my testing, you can't send CTRL-S to a minimized Notepad window and have it do anything with it. It won't save the document, and it won't ask you for a file name to save it to, if it's minimized. At least not with ControlSend. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
jdelaney Posted December 20, 2012 Share Posted December 20, 2012 (edited) Just throwing this out there, because sometimes people ask questions to solve a problem, where there are much easier ways to do the task: Use the FileOpen|FileRead|FileWrite functions Or, rather than 'saving' the text document, why not get the text of all open notepads, and then use the filewrite functions to save to a file...much easier, again (and the window may be minimized) Edited December 20, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
arnabg Posted December 29, 2012 Author Share Posted December 29, 2012 I often use several notepads to write imp content ... diff notepad for diff requirement. sometimes i forget to save some unsaved notepad and loose it if PC shut down. So I need to save notepads in every 5 min automatically If I can't save minimized notepads by autoit ... is there anyway to maximized all notepad windows ... save and minimize those again? like "minimize group"? Pls show code example and how to do it in every 5/10 min ... thanks in advance Link to comment Share on other sites More sharing options...
BrewManNH Posted December 29, 2012 Share Posted December 29, 2012 Look at WinActivate, WinSetState w/@SW_MAXIMIZE as the state to set it to. WinList using the code JohnOne posted above for only getting Notepad windows. Write some code, then come back with any questions if you get stuck. We don't write the scripts for you, we will help you with anything you have managed to write that doesn't work as expected. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
czardas Posted December 29, 2012 Share Posted December 29, 2012 (edited) I think the concept is flawed. It is better to create a backup directory which automatically saves your work in backup files. The following script creates backups of all notepad windows (implementing jdelaney's suggestion). Whether they are saved, maximized or minimized doesn't matter. HotKeySet("{ESC}", "Quit") ; Hit the escape key to quit. ; Run the backup every 1000 ms (the time delay of 1 second is just for testing) AdlibRegister ( "NotePad_Backup" , 1000) ; Change the time delay to a longer period. While 1 ; Keep the script alive. Sleep(100) ; Reduce memory usage. WEnd Func NotePad_Backup() Local $aNotepad, $sText, $hFile, $hPath $aNotepad = WinList("[Class:Notepad]") ; Get all notepad windows. If $aNotepad[0][0] Then ; Notepad windows exist. For $i = 1 To $aNotepad[0][0] ; Run through the list. $sText = WinGetText($aNotepad[$i][1]) ; Get the text from each window. ; Create a backup name. ; Adjust this by including $aNotepad[$i][0] in the title if you wish. $hFile = StringRight(@YEAR, 2) & @MON & @MDAY & StringTrimLeft($aNotepad[$i][1], 2) & ".txt" $hPath = @ScriptDir & "\backup\" & $hFile ; The backup files belong in a backup directory. FileOpen($hPath, 10) ; Creates directory and overwrites any previous backup of the same file. If @error Then ConsoleWrite("File Open Failed with " & $hPath &@LF) ; Check the file isn't read only. FileWrite($hPath, WinGetText($aNotepad[$i][1])) ; Write the contents of the window to the backup text file. If @error Then ConsoleWrite("File Write Failed with " & $hPath &@LF) ; Check the file isn't read only. FileClose($hPath) Next EndIf EndFunc Func Quit() Exit EndFunc This isn't 100% bullet proof all of the time. If you close a window without saving you could still lose some work. If you then start a new instance of notepad, Windows may reassign the same handle, and the new file may overwrite the old one. This can only happen on the same day, but some tweaks to the naming could reduce the risk (see comment - line 19). For Example replace line 20 with this: $hFile = StringRight(@YEAR, 2) & @MON & @MDAY & StringTrimLeft($aNotepad[$i][1], 2) & " (" & $aNotepad[$i][0] & ").txt" If you don't overwrite files you will end up with a bloated folder full of backups. This script is only intended as a precaution. To be absolutely certain, make sure you save your work manually. Also consider that there may be other alternatives which you, or I, haven't thought of yet. Edited December 29, 2012 by czardas Xandy 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
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