mafioso Posted January 24, 2008 Share Posted January 24, 2008 Hello. I am trying to make a logger for my PC. It logs Firefox's title and writes it to the line. But here's the problem : I've created an infinite loop, and script keeps writing to file for ex. hundreds and hundreds of lines while still on the same page. Here's the code, I hope you will understand what I want through code (read comments) : Opt("WinTitleMatchMode", 2) While 1 WinWait ("Mozilla Firefox") $title = WinGetTitle ("Firefox") $file = FileOpen ("logs.txt", 1) FileWriteLine ($file, "Firefox opened at " & @MDAY & " (day in the month) " & @HOUR & " (hour) " & @MIN & " (minutes) " & "Firefox's title: " & $title & " {END OF LOG}" & " -----------") $readline = FileReadLine ($file, 1) $readline2 = FileReadLine ($file, 2) ---If $readline & readline2 are same, then pause the filewriting (while WinGetTitle is still working) UNTIL $title changes--- WEnd So, if $readline & $readline2 are same, I need to pause the writing to the file (something like pausing the loop). WinGetTitle still needs to check, and when $title changes (look at filewriteline), continue loop. I hope you understood me...really hard to explain...When $title changes, then FileWriteLine will write different line (3rd line) than the 1st line...ah... Link to comment Share on other sites More sharing options...
FireLordZi Posted January 24, 2008 Share Posted January 24, 2008 Hello. I am trying to make a logger for my PC. It logs Firefox's title and writes it to the line. But here's the problem : I've created an infinite loop, and script keeps writing to file for ex. hundreds and hundreds of lines while still on the same page. Here's the code, I hope you will understand what I want through code (read comments) : Opt("WinTitleMatchMode", 2) While 1 WinWait ("Mozilla Firefox") $title = WinGetTitle ("Firefox") $file = FileOpen ("logs.txt", 1) FileWriteLine ($file, "Firefox opened at " & @MDAY & " (day in the month) " & @HOUR & " (hour) " & @MIN & " (minutes) " & "Firefox's title: " & $title & " {END OF LOG}" & " -----------") $readline = FileReadLine ($file, 1) $readline2 = FileReadLine ($file, 2) ---If $readline & readline2 are same, then pause the filewriting (while WinGetTitle is still working) UNTIL $title changes--- WEnd So, if $readline & $readline2 are same, I need to pause the writing to the file (something like pausing the loop). WinGetTitle still needs to check, and when $title changes (look at filewriteline), continue loop. I hope you understood me...really hard to explain...When $title changes, then FileWriteLine will write different line (3rd line) than the 1st line...ah... maybe lookup Do..Until While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 25, 2008 Share Posted January 25, 2008 (edited) Just don't write anything in the first place if the title hasn't changed. Also, the title may not contain "Mozilla Firefox", so use the handle. Also, also, the _FileWriteLog() function will add a date/time stamp automatically. Also, also, also, you need a way to exit when the window closes: #include <file.au3> Opt("WinTitleMatchMode", 2) Global $file = "C:\Temp\FFLog.txt" WinWait("Mozilla Firefox") Global $hFF = WinGetHandle("Mozilla Firefox") Global $sTitle = WinGetTitle($hFF) _FileWriteLog($file, "Firefox open, title = " & $sTitle) While WinExists($hFF) $sNewTitle = WinGetTitle($hFF) If $sNewTitle <> $sTitle Then $sTitle = $sNewTitle _FileWriteLog($file, "Firefox changed, title = " & $sTitle) EndIf Sleep(100) WEnd _FileWriteLog($file, "Firefox closed.") Edit: Sleep() added so ReaImDown doesn't fry any more RAM... Edited March 20, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mafioso Posted January 26, 2008 Author Share Posted January 26, 2008 Thanks a LOT ! Link to comment Share on other sites More sharing options...
ReaImDown Posted March 20, 2008 Share Posted March 20, 2008 Just don't write anything in the first place if the title hasn't changed. Also, the title may not contain "Mozilla Firefox", so use the handle. Also, also, the _FileWriteLog() function will add a date/time stamp automatically. Also, also, also, you need a way to exit when the window closes: #include <file.au3> Opt("WinTitleMatchMode", 2) Global $file = "C:\Temp\FFLog.txt" WinWait("Mozilla Firefox") Global $hFF = WinGetHandle("Mozilla Firefox") Global $sTitle = WinGetTitle($hFF) _FileWriteLog($file, "Firefox open, title = " & $sTitle) While WinExists($hFF) $sNewTitle = WinGetTitle($hFF) If $sNewTitle <> $sTitle Then $sTitle = $sNewTitle _FileWriteLog($file, "Firefox changed, title = " & $sTitle) EndIf WEnd _FileWriteLog($file, "Firefox closed.") u missed some sleeps...it will use 99% of the cpu (I learned that the hard way, I fried some ram) [u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u] 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