Wondering if this is possible - different action based on the same image being seen twice

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
hassan
Newbie
Posts: 4
Joined: Wed Jul 10, 2019 3:56 pm

Wondering if this is possible - different action based on the same image being seen twice

Post by hassan » Tue Jul 16, 2019 2:14 pm

Basically I am trying to merge a bunch of duplicates on Pardot and I have figured out coding a macro that - for the most part - works seamlessly every time I run it. Sometimes it clicks on odd spots, but I get the vibe that's something that I just need to put up with.

My question is, is there any way to insert code such that if two of the same image show up in the same "rectangle", the macro goes a different route as opposed to continuing following the remainder of the code?

Basically, if both dupes already exist in Salesforce, I don't want to continue the merge process, I'd rather make a note of it and move on. This requires recognizing both Salesforce cloud icons.

Not sure that's something that can be done, but figured I would inquire.

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

Re: Wondering if this is possible - different action based on the same image being seen twice

Post by Dorian (MJT support) » Tue Jul 16, 2019 10:04 pm

FindImagePos can find more than one image when using EXACT.

Code: Select all

FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0,1,XArr,YArr,NumFound,EXACT
if>NumFound>1
  //Do something
Endif
Yes, we have a Custom Scripting Service. Message me or go here

hassan
Newbie
Posts: 4
Joined: Wed Jul 10, 2019 3:56 pm

Re: Wondering if this is possible - different action based on the same image being seen twice

Post by hassan » Thu Jul 18, 2019 3:30 pm

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore -spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
// C:\Users\hassa\AppData\Local\Temp\msrF347.scp
// Recorded on  Friday, July 12, 2019, at 02:58 PM
 
//Recorded Events
Let>WW_TIMEOUT=5
CapsOff
MouseMove>2970,445
Wait>0.329
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_0.png
Wait>0.001
LDown
//Activating Window: 
//SnapShotFile>%BMP_DIR%snapshot_1.png
MoveWindow>Pardot/Salesforce Duplicates - Google Sheets - Google Chrome,-7,0
ResizeWindow>Pardot/Salesforce Duplicates - Google Sheets - Google Chrome,974,532
Wait>0.061
LUp
Wait>0.186
MouseMove>376,281
Wait>0.242
Press LCTRL
Wait>0.005
Send>c
Wait>0.001
MouseMove>507,287
Wait>0.09
Release LCTRL
Wait>0.001
MouseMove>4574,302
Wait>0.175
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_2.png
Wait>0.029
LDown
//Activating Window: 
//SnapShotFile>%BMP_DIR%snapshot_3.png
 
MoveWindow>Search Results: aadams@tmsd.mb.ca - Pardot - Google Chrome,953,0
ResizeWindow>Search Results: aadams@tmsd.mb.ca - Pardot - Google Chrome,974,1057
Wait>0.062
MouseMove>4327,302
Wait>0.136
LUp
Wait>0.115
Press LCTRL
Wait>0.046
Send>v
Wait>0.001
MouseMove>1169,153
Wait>0.058
Release LCTRL
Wait>0.001
MouseMove>1568,197
Wait>0.978
Press Enter
Wait>0.811
MouseMove>3680,508
Wait>11
//THIS IS WHERE I WOULD NEED THE SCRIPT TO STOP IF IT SEES TWO CLOUDS INSTEAD OF ONE
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_4.png
Wait>0.545
LClick
Wait>0.201
MouseMove>3870,598
Wait>0.194
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_5.png
Wait>0.001
LClick
Wait>0.357
MouseMove>3870,713
Wait>0.474
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_6.png
Wait>0.045
LClick
Wait>0.091
MouseMove>3910,600
Wait>0.252
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_7.png
Wait>0.001
LClick
Wait>1.575
ScreenCapture>4273,458,4653,572,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_3.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+4273},{%YArr_0%+458}
  LClick
Endif
Wait>0.393
ScreenCapture>3652,844,4126,1595,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_10.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+3652},{%YArr_0%+844}
  LClick
Endif
Wait>1
ScreenCapture>4722,847,5208,1595,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Top Left of 
FindImagePos>%BMP_DIR%\image_11.bmp,%TEMP_DIR%\screenrect.bmp,0.3,0,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+4722},{%YArr_0%+847}
  LClick
Endif
MouseMove>XArr_0,YArr_0
LClick
ScreenCapture>3651,911,4113,1605,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_12.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+3651},{%YArr_0%+911}
  LClick
Endif
Wait>0.35
// C:\Users\HASSAN~1.MAH\AppData\Local\Temp\msr7F36.scp
// Recorded on  Monday, July 15, 2019, at 02:31 PM

//Recorded Events
Let>WW_TIMEOUT=5
CapsOff
MouseMove>3068,444
Wait>1.090
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_20.png
Wait>0.062
RDown
//Activating Window: 
//SnapShotFile>%BMP_DIR%snapshot_21.png
MoveWindow>Pardot/Salesforce Duplicates - Google Sheets and 1 more page ?- Microsoft Edge,2729,205
ResizeWindow>Pardot/Salesforce Duplicates - Google Sheets and 1 more page ?- Microsoft Edge,867,712
Wait>0.125
RUp
Wait>0.266
MouseMove>3170,665
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_22.png
Wait>0.25
LClick
Wait>0.21
MouseMove>2470,1090
LClick

That is my code.

I have indicated within my code "THIS IS WHERE"... in order to show the point where this image may show up twice instead of once and how I would like the script to handle that.

Alternatively, I also would like it to stop if it sees NO CLOUDS - but that isn't AS important and as such I'm willing to forego the complication.

If it only sees the one cloud (which is 99.9% of the cases in my experience), it should just go on with the rest of the steps of the script.

Would it be possible to give me a little more guidance as to how to insert the code you have written? I would really appreciate it. The noob next to my name isn't only because I'm new to the forum :P

User avatar
PepsiHog
Automation Wizard
Posts: 454
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Wondering if this is possible - different action based on the same image being seen twice

Post by PepsiHog » Fri Jul 19, 2019 6:57 pm

@hassen,
You already know how to use FindImage and ScreenCapture. You only need to do the same thing where you indicated. Only this time your image will be double. In the if> statement if it finds the double image then do something else or exit.

Subroutines are easy to use and allow you to call them when they are needed. One sub could check for a double image. Another could check for a single image. Yet another could perform certain actions. You may want to check it out.

You may also benefit from changing your var names in your FindImage commands. The one that checks for a single image could be SingleX,SingleY instead of XArr,YArr. Your numFound could be SingleNum. In this way, you can refer back to them any where in the macro.

Hope this helps, and good luck,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2020) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
PepsiHog
Automation Wizard
Posts: 454
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Wondering if this is possible - different action based on the same image being seen twice

Post by PepsiHog » Fri Jul 19, 2019 7:28 pm

@hassen

Here is an example of using subroutines. I took the first part of your script and enclosed it in a subroutine. The subroutine name is up to you. You call it using gosub>. It will run the subroutine and then return to the next line after the gosub> that called it. I moved the subroutine to the bottom of the script to show that the subroutine can be any where in your script. It gets executed only when you call it with gosub.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore -spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
// C:\Users\hassa\AppData\Local\Temp\msrF347.scp
// Recorded on  Friday, July 12, 2019, at 02:58 PM


GoSub>RecordedEvents


//Activating Window: 
//SnapShotFile>%BMP_DIR%snapshot_1.png
MoveWindow>Pardot/Salesforce Duplicates - Google Sheets - Google Chrome,-7,0
ResizeWindow>Pardot/Salesforce Duplicates - Google Sheets - Google Chrome,974,532
Wait>0.061
LUp
Wait>0.186
MouseMove>376,281
Wait>0.242
Press LCTRL
Wait>0.005
Send>c
Wait>0.001
MouseMove>507,287
Wait>0.09
Release LCTRL
Wait>0.001
MouseMove>4574,302
Wait>0.175
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_2.png
Wait>0.029
LDown
//Activating Window: 
//SnapShotFile>%BMP_DIR%snapshot_3.png
 
MoveWindow>Search Results: aadams@tmsd.mb.ca - Pardot - Google Chrome,953,0
ResizeWindow>Search Results: aadams@tmsd.mb.ca - Pardot - Google Chrome,974,1057
Wait>0.062
MouseMove>4327,302
Wait>0.136
LUp
Wait>0.115
Press LCTRL
Wait>0.046
Send>v
Wait>0.001
MouseMove>1169,153
Wait>0.058
Release LCTRL
Wait>0.001
MouseMove>1568,197
Wait>0.978
Press Enter
Wait>0.811
MouseMove>3680,508
Wait>11
//THIS IS WHERE I WOULD NEED THE SCRIPT TO STOP IF IT SEES TWO CLOUDS INSTEAD OF ONE
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_4.png
Wait>0.545
LClick
Wait>0.201
MouseMove>3870,598
Wait>0.194
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_5.png
Wait>0.001
LClick
Wait>0.357
MouseMove>3870,713
Wait>0.474
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_6.png
Wait>0.045
LClick
Wait>0.091
MouseMove>3910,600
Wait>0.252
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_7.png
Wait>0.001
LClick
Wait>1.575
ScreenCapture>4273,458,4653,572,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_3.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+4273},{%YArr_0%+458}
  LClick
Endif
Wait>0.393
ScreenCapture>3652,844,4126,1595,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_10.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+3652},{%YArr_0%+844}
  LClick
Endif
Wait>1
ScreenCapture>4722,847,5208,1595,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Top Left of 
FindImagePos>%BMP_DIR%\image_11.bmp,%TEMP_DIR%\screenrect.bmp,0.3,0,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+4722},{%YArr_0%+847}
  LClick
Endif
MouseMove>XArr_0,YArr_0
LClick
ScreenCapture>3651,911,4113,1605,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_12.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>{%XArr_0%+3651},{%YArr_0%+911}
  LClick
Endif
Wait>0.35
// C:\Users\HASSAN~1.MAH\AppData\Local\Temp\msr7F36.scp
// Recorded on  Monday, July 15, 2019, at 02:31 PM
//Recorded Events
Let>WW_TIMEOUT=5
CapsOff
MouseMove>3068,444
Wait>1.090
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_20.png
Wait>0.062
RDown
//Activating Window: 
//SnapShotFile>%BMP_DIR%snapshot_21.png
MoveWindow>Pardot/Salesforce Duplicates - Google Sheets and 1 more page ?- Microsoft Edge,2729,205
ResizeWindow>Pardot/Salesforce Duplicates - Google Sheets and 1 more page ?- Microsoft Edge,867,712
Wait>0.125
RUp
Wait>0.266
MouseMove>3170,665
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_22.png
Wait>0.25
LClick
Wait>0.21
MouseMove>2470,1090
LClick


srt>RecordedEvents
//Recorded Events
Let>WW_TIMEOUT=5
CapsOff
MouseMove>2970,445
Wait>0.329
//Clicking on: 
//SnapShotFile>%BMP_DIR%snapshot_0.png
Wait>0.001
LDown
  
END>RecordedEvents

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2020) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

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