Window focus based upon a notification sound

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

stearno
Junior Coder
Posts: 22
Joined: Sun Jul 26, 2020 4:15 am

Window focus based upon a notification sound

Post by stearno » Tue Jul 28, 2020 8:53 am

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?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Window focus based upon a notification sound

Post by Dorian (MJT support) » Tue Jul 28, 2020 10:13 am

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.
Yes, we have a Custom Scripting Service. Message me or go here

stearno
Junior Coder
Posts: 22
Joined: Sun Jul 26, 2020 4:15 am

Re: Window focus based upon a notification sound

Post by stearno » Tue Jul 28, 2020 10:41 am

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?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Window focus based upon a notification sound

Post by Dorian (MJT support) » Tue Jul 28, 2020 11:30 am

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.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Window focus based upon a notification sound

Post by Dorian (MJT support) » Tue Jul 28, 2020 12:40 pm

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".
Yes, we have a Custom Scripting Service. Message me or go here

stearno
Junior Coder
Posts: 22
Joined: Sun Jul 26, 2020 4:15 am

Re: Window focus based upon a notification sound

Post by stearno » Tue Jul 28, 2020 3:50 pm

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....

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Window focus based upon a notification sound

Post by Dorian (MJT support) » Tue Jul 28, 2020 4:03 pm

What about ReadFile, and then just get the length?
Yes, we have a Custom Scripting Service. Message me or go here

stearno
Junior Coder
Posts: 22
Joined: Sun Jul 26, 2020 4:15 am

Re: Window focus based upon a notification sound

Post by stearno » Tue Jul 28, 2020 4:23 pm

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.

stearno
Junior Coder
Posts: 22
Joined: Sun Jul 26, 2020 4:15 am

Re: Window focus based upon a notification sound

Post by stearno » Tue Jul 28, 2020 4:29 pm

Dorian (MJT support) wrote:
Tue Jul 28, 2020 4:03 pm
What about ReadFile, and then just get the length?
It turns out the log is not updated in real time...

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Window focus based upon a notification sound

Post by Dorian (MJT support) » Tue Jul 28, 2020 5:54 pm

How about we take a step back. What if you simply rotated through the windows, focusing each, and looked for the image each time?
Yes, we have a Custom Scripting Service. Message me or go here

stearno
Junior Coder
Posts: 22
Joined: Sun Jul 26, 2020 4:15 am

Re: Window focus based upon a notification sound

Post by stearno » Tue Jul 28, 2020 6:04 pm

stearno wrote:
Tue Jul 28, 2020 4:23 pm
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.
Haha, great minds think alike! I came up with same solution.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Window focus based upon a notification sound

Post by Dorian (MJT support) » Tue Jul 28, 2020 6:19 pm

Aah, I missed that reply.

In answer to your question :

https://help.mjtnet.com/article/14-why- ... logged-out
Yes, we have a Custom Scripting Service. Message me or go here

stearno
Junior Coder
Posts: 22
Joined: Sun Jul 26, 2020 4:15 am

Re: Window focus based upon a notification sound

Post by stearno » Tue Jul 28, 2020 6:24 pm

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.

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Window focus based upon a notification sound

Post by JRL » Tue Jul 28, 2020 10:47 pm

I wrote THIS a few years back. It might be useful or it might not be useful.
Hope it helps.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Window focus based upon a notification sound

Post by Dorian (MJT support) » Wed Jul 29, 2020 7:57 am

JRL wrote:
Tue Jul 28, 2020 10:47 pm
I wrote THIS a few years back. It might be useful or it might not be useful.
Hope it helps.
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.
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts