Send msg_txt fra liste Macro (v11.0.3)

Send msg_txt fra liste Macro (v11.0.3)

Send msg_txt fra liste.kmmacros (28 KB)

The scope of the macro is (be aware - it is my first KM macro):

  1. For each row in the excel, use content:columnB as clickable url in Facebook to get the right person - and send the personalized message:columnC. Set columnD=sent. Save excel sheet.
  2. Next row.

A couple of problems present themselves:

  1. If you've got 4k+ rows to work through, there's a good chance of something going wrong -- as it stands, you've no idea of how far you got before that happened (I've just seen you've included a "Sent" column in your description, so that's covered)
  2. As written, your Excel keystrokes keep moving you down and right through the cells -- you never go back to the left again
  3. You should use something other than a typed string, to reduce the risk of unwanted deletions when you fire this with the "wrong thing" active. You could even use the "Run" button in the KM Editor, since it hardly seems worth setting up an hotkey trigger for a seldom-run macro

I'd open both the Excel document and the Facebook page manually, before starting the macro. That lets you check that the correct starting cell is selected in the spreadsheet and that your Facebook account is logged in and ready to go.

The other problem is when to stop your loop. Excel's "Copy" item is available even when a cell is empty, so the easiest way will be to "Copy" anyway but stop if the System Clipboard is empty.

Given that starting point, the pseudocode for the macro could be

activate spreadsheet
copy cell contents
while system clipboard is not empty
   set variable 'Local_url' to the system clipboard contents
   keystroke right-arrow
   copy cell contents
   set variable 'Local_message' to the system clipboard contents
   activate Chrome
   set the Chrome window URL to 'Local_url'
   pause until the image of the "Message" button is detected in the front window
   click the image of the "Message" button
   -- you may have to add another pause to wait for the message field to come up
   set the message text field to 'Local_message'
   keystroke 'Return' -- I assume that sends the message
   activate spreadsheet
   keystroke right-arrow
   insert text by typing: 'x' -- mark the line as processed
   keystroke 'Return'
   keystroke left-arrow
   keystroke left-arrow -- now back on the 'url' cell of the next row to process
   save the spreadsheet
   copy cell contents
end while

Most of that should be directly translatable to KM actions, but you should miss out the actual sending of the message until you've tested your macro and are happy with it!

Have a go, see how you get on -- and ask if anything above isn't clear.

Hi Nige,
Thank you for very valuable guidance. Most appreciated.
Question though...
The macro went well all the way until the Message button was to be found.
It has worked earlier (I think) so there must be something with the parameters.
Any guidance on that? See original share of macro - no change on that part, also uploaded now.
Based on your input I will also change the macro to loop 100 per loop...
/morten

Start by putting a "Pause" action immediately before it, to make sure the page has time to load before you look for the button. Easy troubleshooting is to make it 5 seconds, to be really sure. If that solves the problem you can change it to a "Pause Until...", using a "Found image" condition that waits for the same image as the one you are going to click:

image

You test the "Click at...." action's image detection by manually loading the Facebook page then using the action's "Go" button to see if the image is detected. You may have to adjust the "fuzziness" slider to get a match (web pages can vary when rendered) and you may have to pick a different "Display" option if the image occurs more than once on the web page:

Make sure you have Notifications enabled since KM will put up a Notification to tell you if there's a problem matching the image.

Assuming that the Facebook page is the front window when you get to this stage of the macro, I'd also limit the "Pause" and "Click" image detection to just the front window, as shown above, to help prevent false positives.

Thanks again, and I have tried to make the changes but the macro seems to stop at the same place. Any idea? I can make a video-recording if that will help?

It will certainly stop -- you've got a "Breakpoint" action so it will stop and open the Debugger. Is that what you mean, or does it not continue after you click on the Debugger's "Continue", "Step Over" or "Step Into" buttons?

If the macro continues but aborts on the "Move and Click" action, what error do you get (in either the Notification or the when you view the Engine log at ~/Library/Logs/Keyboard Maestro/Engine.log)?

Hi,
thanks again for helping out.
As I see it the stop has nothing to do with the debugger but here is a video link - maybe this will help out.

The log:
2024-11-19 16:43:15 Execute macro “Stop KeyboardMaestro” from trigger Editor
2024-11-21 10:25:05 Execute macro “Stop KeyboardMaestro” from trigger Editor
2024-11-21 10:25:36 Execute macro “Send msg_txt fra liste” from trigger Editor
2024-11-21 10:25:50 Screen Recording is disabled
Last message repeated 2 times
2024-11-21 10:25:51 HScreenArea::CaptureCGImage failed to capture front window
2024-11-21 10:25:51 MatchImage::Match failed to create source image: failed to capture front window (Screen Recording is disabled)
2024-11-21 10:25:51 Action 2461 failed: Click at Found Image failed with error failed to capture front window (Screen Recording is disabled)
2024-11-21 10:25:51 Click at Found Image failed with error failed to capture front window (Screen Recording is disabled). Macro “Send msg_txt fra liste” cancelled (while executing Move and Click at (0,0) from the Center of the Found Image).

The breakpoint action will cause the macro to stop at that point -- that's its job!

I'm afraid a zero-second video doesn't help much, but the logs do:

2024-11-21 10:25:50 Screen Recording is disabled

You can't do image detection if you've not allowed screen recording. Check your System Settings -> Privacy & Security -> Screen & System Audio Recording and make sure Keyboard Maestro has been enabled.

Screen Recording was already enabled in Settings.
When I look at the video in Dropbox - it is very much live and correct.
Try once more, please:

Seems I cannot share link to videos. Also tried to upload - negative.

If you look carefully at the steps everything goes smooth until this breakpoint before "Move and Click"

...which is equivalent to this part of the video:

...and when I click step, this is the result:

...and it stays like that until I stop/cancel the macro/all macros.

Hope this helped.

Then check Keyboard Maestro's Settings:

Thank you again.
Sorry for the late response but I had to drive my RV 3200km for repair and that took a few hours to do...
I have just checked and it look all good to me also on preferences for KM. See upload.

I'm afraid you'll have to troubleshoot this yourself, as it's something particular to either your machine or that web page.

As always -- if it was working but isn't now, what's changed?

Delete the "Debugger" actions in case they are interfering somehow. Try some image detection on another site -- this one, for example -- to check it isn't a general problem. Try Safari instead of Chrome.

Not being a Facebook user I can't suggest ways to simulate clicks on those elements via JavaScript -- perhaps someone else will step in.

well, this has never been working in its full before.
Thank you for trying - I will have to try to find another person to help out.