Window focus based upon a notification sound
Moderators: JRL, Dorian (MJT support)
Window focus based upon a notification sound
My objectcive. I have 3 weindows open. They are too big to have all three on the screen at the same time. When a window triggers a notification, I want the Macro to bring it into focus and then image recognition to start. Is this possible?
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Window focus based upon a notification sound
Is the notification only a sound? Or is there some kind of popup or another kind of visual change in any way?
If it's a notification pop-up, then depending on the popup, maybe. Look at Triggers. The Window Event trigger may be what you need, if it is indeed a window event.
If it's a notification pop-up, then depending on the popup, maybe. Look at Triggers. The Window Event trigger may be what you need, if it is indeed a window event.
Re: Window focus based upon a notification sound
It is a sound only produced by a software. After the sound an image pops on an existing window. That image, I want the MS to recognize it and take action. But I need to tell MS to focus on the window first.
I think what I can do is, it does write a line in a log when this sound goes off. I could have something read the txt file, when that line appears with the word, then focus on that window.
Does that sound like the only option?
I think what I can do is, it does write a line in a log when this sound goes off. I could have something read the txt file, when that line appears with the word, then focus on that window.
Does that sound like the only option?
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Window focus based upon a notification sound
That sounds like a good option. In the Trigger section I linked above, look for Custom Triggers. I see no reason why you can't make a custom trigger which monitors a file to see if it's updated.
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Window focus based upon a notification sound
First of all, follow the instructions here.
But use the attached files. You'll need to edit the paths of course. But this works, and will get you started. It's a custom trigger based on the file size changing.
Trigger01 Create Ini will create an original an ini file containing the current file size. Just run this once (after editing the path to point to your log file).
Trigger01 reads the ini file and compares it to the current file size. Trigger01-Action is the file that "does something".
But use the attached files. You'll need to edit the paths of course. But this works, and will get you started. It's a custom trigger based on the file size changing.
Trigger01 Create Ini will create an original an ini file containing the current file size. Just run this once (after editing the path to point to your log file).
Trigger01 reads the ini file and compares it to the current file size. Trigger01-Action is the file that "does something".
Re: Window focus based upon a notification sound
Unfortunately, it has much text written into the file. So its size will not be a good trigger.
Using ReadLn, how can I know how many lines in the log file or make it go to the last line?
I guess, worst case scenario, I could set it as a big number, then loop it to go backwards until it does not get an error....then I would know the last line....
Using ReadLn, how can I know how many lines in the log file or make it go to the last line?
I guess, worst case scenario, I could set it as a big number, then loop it to go backwards until it does not get an error....then I would know the last line....
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Window focus based upon a notification sound
What about ReadFile, and then just get the length?
Re: Window focus based upon a notification sound
I think maybe its easiest to MS just focus on one screen at a time and rotate every x seconds.
By the way, does the Image Recognition work when monitor is turned off (specifically, I have MS running on a server when I am not connected to it). If you don't know, then I will find out soon.
By the way, does the Image Recognition work when monitor is turned off (specifically, I have MS running on a server when I am not connected to it). If you don't know, then I will find out soon.
Re: Window focus based upon a notification sound
It turns out the log is not updated in real time...Dorian (MJT support) wrote: ↑Tue Jul 28, 2020 4:03 pmWhat about ReadFile, and then just get the length?
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Window focus based upon a notification sound
How about we take a step back. What if you simply rotated through the windows, focusing each, and looked for the image each time?
Re: Window focus based upon a notification sound
Haha, great minds think alike! I came up with same solution.stearno wrote: ↑Tue Jul 28, 2020 4:23 pmI think maybe its easiest to MS just focus on one screen at a time and rotate every x seconds.
By the way, does the Image Recognition work when monitor is turned off (specifically, I have MS running on a server when I am not connected to it). If you don't know, then I will find out soon.
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Window focus based upon a notification sound
Aah, I missed that reply.
In answer to your question :
https://help.mjtnet.com/article/14-why- ... logged-out
In answer to your question :
https://help.mjtnet.com/article/14-why- ... logged-out
Re: Window focus based upon a notification sound
Okay, I figured that was true (as it's logical) . Thought best to ask, just to be sure. Thanks for confirming and all your help.
Re: Window focus based upon a notification sound
I wrote THIS a few years back. It might be useful or it might not be useful.
Hope it helps.
Hope it helps.
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: Window focus based upon a notification sound
That's very clever. Thank you, Dick. That makes me wonder if simply using GetPixelColor on that would work. I hadn't ever noticed the colour changes when it plays a sound. I'm using Win10. I'll check later.