if function with image

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Filiep
Newbie
Posts: 2
Joined: Wed Mar 02, 2016 9:26 am

if function with image

Post by Filiep » Mon Mar 21, 2016 7:41 pm

Hello,

I want my spotifyplayer to keep playing. Sometimes the connection drops. So I want the macro to check the status of the player.
If it is playing it has to do nothing.
If it is disconnected it has to refresh and play
If it stoped playing it has to play again

So that means.

The macro has to look for certain images. If it finds those images it has to take action. If I use the find image wizard I can't select a action.

find disconnect image
if found execute refresh
if not found continue

find play button image
if found press button
if not found continue

execute refresh subroutine
press F5
wait for play button image to appear then continue script


I don't know if this is possible.

thx

Filiep

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: if function with image

Post by Marcus Tettmar » Tue Mar 22, 2016 9:07 am

Yes, you can do this.

With the image recognition wizard you can create the code to look for the image. You would then insert the code needed to execute the actions - e.g. refresh. Which I assume is just F5 (making sure Spotify has focus).

You can insert whatever code you want and use whatever logic you need. So it sounds like you want something like this:

Code: Select all

//first make sure Spotify has focus (I'm guessing the window title - adjust accordingly):
SetFocus>Spotify*

//Look for the disconnect button 
FindImagePos>%BMP_DIR%\disconnect.bmp,SCREEN,0.7,1,X,Y,NumFound,CCOEFF
If>NumFound>0
 //We found the disconnect button, so refresh ....
 Press F5
 // now wait for play button to appear
 WaitScreenImage>%BMP_DIR%\play.bmp,0.7,CCOEFF
Endif

//Look for play button and click on it ... 
FindImagePos>%BMP_DIR%\play.bmp,SCREEN,0.7,1,X,Y,NumFound,CCOEFF
If>NumFound
 //found play button, click it
 MouseMove>X_0,Y_0
 LClick
Endif
Note this is an *untested example* to demonstrate an idea of what you want to do. You would need to capture the images and check the window titles etc.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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