Hi folks. I want to create a KM macro for Apple Mail that—in an outgoing email I'm writing…
• Initiates a Find
• Pastes a bullet (•) into the find field
• Finds the first bullet, then selects from the found bullet to the end of that line, and deletes.
• Continues doing so until all bulleted lines are dealt with.
So as an example, if I were composing an email with this in it:
Some text • sadly sldkjf asdlkfj
More text • la la la la
Still more text • blah blah blah
Wee wee oui oui • la dee dah
… it would end up like this:
Some text
More text
Still more text
Wee wee oui oui
Easy, I'm sure. I just don't know how to have KM know when there are no more bullets left. My posted macro is fine except for that. I just have it repeating however many times just to make sure it worked as is… which it does.
Anyone care to help me do a KM macro that would accomplish this with more finesse?
I apologize for not understanding. When you say "if I had an email" are you talking about mail in your Inbox? I don't think you can edit mail that's in your Inbox. Or are you talking about a message that you are currently drafting? I won't even be able to download and test your macro unless I understand the context that I have to set up to make your macro work. I apologize again for not understanding.
The solution to that is (could be) to use the "Replace all" feature which exists in most apps including mail. However I don't think Apple Mail's GUI supports regex, which is probably what you need to solve this efficiently using "replace all." But the Apple Mail GUI (for certain types of find/replace) does change the colour of the screen after it's finished finding all the occurrences, therefore it is possible for Keyboard Maestro to use this fact to detect that the Find/Replace has completed. But before I write any such code for you, I would like more context which I requested in my previous paragraph.
Oh, good point, Airy. Sorry for being unclear. I edited my original post to address my unclarity.
Yes, this would be for an outgoing email that I am in the process of composing.
The "Replace All" option wouldn't work because the text following each bullet will be different. The bullet i there so I can search for a bullet and delete from the bullet to the end of the line, for each line that contains a bullet.
That is clearer, thanks. I think it may be possible using Find Image to detect subtle changes on the screen when the last item is found, but I have to step out now.
There's also a 20% chance that this can be solved a completely different way using AppleScript, but I wont' be able to help with that.
A different approach would be to copy the text of the email to the system clipboard and then use a regular expression search and replace to remove the text you don't want, then paste it back. Something like this:
In case it's difficult to see in the image, the regex is (?m)•.+$
Set a hotkey trigger for that macro, then with the cursor in the body of the email, trigger the macro and it should do what you want. A quick test here in mail based on the example you gave removes everything from the bullet to the end of the line. Note that it will leave your email on the clipboard - if that's a problem you could remove it by adding a "Delete Past Clipboard 0" action to the end of the macro.
That's a great idea, but only if he doesn't have rich text formatting or images in his email message. Of course, he didn't say he needed to support rich text, so your solution would work in that case.
Thank you, Roger. In fact, Airy is right: I do need rich text, because before I get rid of my bullets and the rest of their lines, I'm going to bold some of the text that is going to stay.
Okay, then I'll put some thought into a solution. But I will still say that you are making your life much tougher by bolding text before you remove the bullets. I will still help, because I like a challenge, but it's going to be tougher for you.
I've already got an interesting idea which I'm testing now.
Okay, it seems to be working. Let me clean it up and post it in a few minutes.
Okay, this macro works for me. Bear in mind that your screen resolution may be different from mine so you may have to load the image wells with different images. But your image still has to look EXACTLY like mine. I'm using some advanced trickery to make this work, and for the moment I'm asking you to do exactly as I do, before I explain all the trickery. Furthermore, some of the constants in this macro may have to be replaced if your screen has different DPI than mine.
All these annoyances could be eliminated if you used the other method above, but it's always fun to learn, and if you can adapt this macro to suit your needs, you will learn a lot.
Remove Bullets from Composing Message Macro (v11.0.3)
Ha! Well, I hear you, but what this is actually going to be is a list of dates, and the text after the bullets tells me which dates are the most desirable, and I put those dates in bold, and then get rid of the data after the dates, because the client has no interest in that. It’s just for me. I suppose I could do something other than using bold, now that I think about it. Like adding an asterisk on the especially good dates, or something
Whatever your use case is, feel free to try to adapt my macro to your situation. If you are using an M3 iMac's default screen in its default resolution, the macro may work as is. If you have a different display resolution, you may have to update the macro. I'll help if you get stuck. However I leave on a vacation in a few days and you might have to rely on others during that time.
Thank you, everyone, for your help. I ended up deciding to deal with this in Filemaker, before exporting the list of dates to email, so I could deal with this in a Filemaker script rather than using any of these KM ideas.
For the record, one of my "sneaky tricks" in my code above was that Apple Text Recognition does not recognize a single character (or number) by itself, so my trick was to include the "(X)" icon after the number as part of the OCR area. By adding that to the OCR action, it is able to read single digit numbers. Then I strip out the X, and I'm able to keep the digits only.