Block and Junk Mail

Need some help debugging. This macro blocks the sender of the currently selected mail message and then moves it to the junk mail folder. It worked fine for months, then it stopped working last week. Not sure why, but possibly new OS release, or new KM release. Who knows? The problem is that the position of the "from:" text field in a mail message is all of a sudden now "off" a few pixels. As a temporary workaround, I biased the X and Y coordinates of its position a few pixels {15, 10} and now it works again. But I would like a permanent solution in case it happens again. I tried to involve the "size" property, but could not get that to work. Any ideas?
Block and Junk.kmmacros (12.6 KB)

I think the solution you have is very good (and it works on my Mac with or without the offset). Those two AppleScripts that get the mouse into the correct place to click are very powerful. Knowing that you might need to tweak the offset a bit as things move forward feels not too bad.

The only alternative way I found to get the mouse to right-click in the correct position was to open the selected message in a new window, and then the coordinates to click on the Sender would be fixed relative to the window's top left corner. As the later Action "Move to Junk" closes the window this kind of worked.

EDIT - one thing I noticed in your Macro is that you have a pause Action waiting for a Menu Item to be enabled. You have it waiting for "Message" to be enabled but I think it should be waiting for "Move to Junk" to be enabled. You had the Action disabled (maybe because it didn't work) but I think it's good to have it in there to allow the System to catch up.

I'm having trouble working out what you are doing, but it looks like you are using AS UI Scripting to get the coordinates of an UI element, then telling KM to click there (now, with an offset).

Can you not just activate the menu in the AppleScript instead?

tell item 1 of UI elements of text area 1 of group 1 of group 1 of scroll area 2 of theSplitterGroup to perform action "AXShowMenu"

You may even be able to AS the menu item selection...

Nice_S. I like this solution. Thank you. It's safer, but it's slow. My earlier one is less safe, but much faster. So, unless I can figure out how to speed up the use of AXShowMenu version, not sure which version is better. I tried a few different solutions including embedding the menu item selection in AS. Maybe there's a better way. Can you think of a way to make your solution run faster? (Enclosing both versions).
Block and Junk less safe but fast.kmmacros (12.6 KB)
Block and Junk more safe but slow.kmmacros (6.4 KB)

Thanks. See my recent post. I disabled the “pause until” since it didn’t always work as I expected.

I like this solution a lot. I’ll try it out for a few days, but so far it looks both fast and safe. Thank you.

1 Like

It's instant for me, running from Script Editor -- macOS 12.6. But UI scripting can perform very differently in different situations. If it's slow for you then use @Zabobon's method, and tweak it when Apple change the element's position again! (Mind you, they're equally likely to change the nesting of the UI elements :wink: )

1 Like

So far, I like @Zabobon's method best. It seems safe and fast.

Block and Junk .kmmacros (5.3 KB)

1 Like