Jump to content

Counting a repetitive process to a file, problem


Kaitsu
 Share

Recommended Posts

Hi, I am fairly new to AutoIt scripting. I would like to make a simple counter that writes a line (date + timestamp) to a text file everytime a window appears. My code works on some level. I use windows calculator in this example.
 
It waits for the window to appear and then writes on the text file ok. But there are 2 questions. The first one is that it floods the txt file with lines as long as the calculator-window is open. I would want only one line for every instance the calculator-window opens. And the second question is how can I loop it so that when calculator opens it writes the line to the txt-file and then waits again for calculator to open and writes again. So a simple log-file is what I am trying to do. Thanks in advance for your help!
 
WinWait("Calculator")
If WinActive("Calculator") Then
 
$file = FileOpen("d:tempcounter.txt", 1)
If $file = -1 Then
    Exit
EndIf
FileWriteLine($file, "Opened, " & @MDAY & "." & @MON & "." & @YEAR & " " & @HOUR & ":" & @MIN & @CRLF)
FileClose($file)
 
ElseIf
WinWait("Calculator")
EndIf
Edited by Kaitsu
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Can you please describe why you want to monitor the number of times a window is opened? What do you try to achieve?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Can you please describe why you want to monitor the number of times a window is opened? What do you try to achieve?

Hi,

Actually I am trying to make a simple report from the data that this little counter should give me. It would then tell me how many times a day the process/window appears and the exact time of day that this occurs. So it would give me a nice simple report. The actual window in my final version that appears is more like "operation successful". And I am trying to count/monitor these processes.

I am a part of a small business. And we have 8 computers on which this little counter should be used to write on a single file which is on a shared network drive. The window I am trying to count is a "ok/done -confirmation window" that is the repetitive process, that a user must click. It would then give us a report how many times the process has been done. Hope this clears:)

Edited by Kaitsu
Link to comment
Share on other sites

Depending where on the world you are located it might be needed to check this with the works council.

I would use function WinList. Each window is returned with a handle. By comparing the handle you can make sure to only count unique windows.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Depending where on the world you are located it might be needed to check this with the works council.

I would use function WinList. Each window is returned with a handle. By comparing the handle you can make sure to only count unique windows.

 

I am from Finland. And it should be completely legal and almost everything else is monitored for reports. This was just my idea that we could monitor it using AutoIt. I will try to look on the WinList function. Seems a bit confusing, but might take a while to figure it out.

In my case the window is always closed after it appears, so there is just one window open at a time.

Edited by Kaitsu
Link to comment
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
 Share

  • Recently Browsing   0 members

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