Macro to move messages in Apple Mail, to replace Mail Act-On?

[quote="griffman, post:20, topic:36725"]
You should give each new macro you create a single key shortcut. The overall macro, as I wrote it, is triggered when you hit Shift-Control-F. That presents the palette which will show any macro within the group. [/quote]

I tried that key-combo to bring up the Palette, and again got this:

...which, again, has me wondering if Act-On is over-riding Keyboard Maestro (when I'm in Mail)

[quote]
And next to each macro the single key shortcut you assigned will appear. Press that key and the selected message(s) will be moved to the mailbox in the macro.[/quote]

OK, I understand that now. But here's the thing: that adds a step to what I'm accustomed to with Act-On: first the Palette, then the specific "Move" macro. Is there not a way to create the Macros outside of the pallette, so that I can just, as I've been doing, hit the combination of +X to move to that Mailbox?

[quote]
And that's the key: There's no magic integration with Mail, you have to enter the name of each mailbox you want to use in each macro you create. [/quote]

That I don't have a problem with.

The issues now are

  • Can I get these Macros to work without a Palette?

  • Don't I have to do anything to Save a Macro I've created? Because it sure seems like they're not Saved, which brings me to

  • Are they in fact "Saved" but the reason they're not executing is because Act-On is commandeering the keyboard?

That last one I'm afraid there maybe be only one way to answer.

Which will, I guess, be the next thing I try while waiting for the next reply here.

Thanks,

--PS

I deactivated Mail Act-On. The "no such command" message doesn't come up, but I'm still get the little 'boop' when I try to execute the Macros I've created.

I have to run now, I guess I'll be back at this tomorrow afternoon.

So, again, I just have to say: this should be easier. I've been struggling to create ONE MACRO for three days now.

----PS

Yes. At the top of the Macro, where you see Shows A Palette For One Action When, change that selection to Always Activated.

No saving is necessary. Keyboard Maestro handles it. Need proof? Use Keyboard Maestro > Quit Keyboard Maestro Editor then re-launch Keyboard Maestro and you'll see everything you've already done remains.

Bonus Tip: Also under the File menu is Revert Macros, which allows you to move back a few iterations to the state where your macros previously were.

It probably is because of Act-On, but since I don't have Act-On it's difficult to be certain. Is there a way to Pause or Deactivate Act-On without something dramatic like uninstalling it?

Let's come back to this for a moment:

This can be done, as already described. But note, Keyboard Maestro Macros do not have an Undo function. So if Mail is your front-most app, and some message is selected, an accidental key press matching any of the shortcuts you create will move the selected message. Put another way,

If you have Keyboard Maestro Macros activated by a single key, they could be easily be inadvertently invoked, and there is no built-in way to Undo the resulting Move of a Message.

OK, I think... we're at the threshold of success!

Or... more accurately, have the first foot across it.

I have a Macro that works!!!!!!

#LittleVictories!!!!!

I do believe that Mail Act-On being activated was one of the impediments.

I am at this time not 100% what exactly I did that got the Macro to work, but it does.

I am going to attempt another one, and a couple more after that. If they all work, then I can finally proceed with my upgrade to Sonoma.

Am truly grateful for the assistance. Thanks for hanging in there with me.

--PS

It's not necessary to re-create each Macro from scratch. Selecting the one that's been made and using Edit > Duplicate or Right-Click > Duplicate will make it so it's only necessary to edit the details (Hot Key, Mailbox destination).

That's exactly what I've done.

I've created two more that way, and so far it seems that sometimes they work and sometimes they don't.

So now I'm troubleshooting.

Thanks,

--PS

OK, I think I've cracked the code!

I'd been creating the Macros by kinda manually typing things in.

Then I discovered the 'Menu' tab to the right of the panel, just below the gear wheel...

... which actually steps through all the actual menus and folders until I find the one I'm building that Macro for:

..and then I wind up with a clean and precise Macro that does exactly what I want it to.

I think I have both feet through the threshold now.

And, sadly for them, will never need Mail Act-On again.

--PS

1 Like

Yes it was just for the practical purpose mentioned (or two purposes, if we separately consider those who may be able to contribute information and those who may want it).

I'm not exactly sure what you mean about robustness causing things to be opaque. KM is certainly offers a deep set of features but we all learn as we go along. The documentation is IMO opaque in places but it is wide-ranging, and the forum is always here to help.

It would of course be unrealistic to expect Keyboard Maestro to come with a ready-to-go drop-in macro replacement for any given commercially developed piece of software, and in more general terms, often things just beneath the surface on the Mac are nowhere near as simple as they may seem.

You've seen by now that a lot of help from other users is offered here when possible and that you are not wading alone. I'm glad light appeared at the end of the tunnel (to suddenly switch metaphor).

It might be that your expectations of what KM have been disappointed. New users do perhaps often expect KM to be more of a push-button way to fully automate all aspects of their Mac. I expect I did too (it was a long time ago). That isn't possible, and if it were, a simplistic, broad approach would limit what KM can do. It provides a lot of power to control quite obvious and more obscure aspects of one's Mac, presented in a user-friendly editor. It's a form of programming, and although it's not aimed just at programmers. Some assembly is definitely required! But is also often desirable.

Since you mention it, I thought that came across as a petulant response to @NaOH's efforts at helping. Other than the developer (who also goes beyond the call of duty), we in the forum are all fellow users of KM here volunteering help so I don't think that was called for.

Moving on, to clarify, I wasn't telling you to change your email program. I was informing you about options (KM is great and all, but when Apple removes functionality from its apps, it's perhaps a time to take a wider view of what's on offer) and letting you know about previous discussions in the forum which I thought you might have missed (while wading! :wink:).

I hope you will increasingly find KM less frustrating, and more fun, to use.

This is most likely because you haven't "Enabled" the macro group -- as a security measure, imported groups/macros are disabled so you can check them out before using them.

Your screen shot in this post shows the "app-Mail Filing" group greyed out, indicating that (then, at least) it's disabled.

Searches are constrained to the current selection -- useful, but it will catch you out. If you aren't seeing what you hope/expect, always check that "All Macros" (when searching for macros) or "All Actions" (for actions) is selected.

Yes. In fact, @griffman's taken you straight to KM Mastery, Level 3 with his "call up a palette of macros, activated for one action".

Level 1 would be "give each macro a different hot key" -- easy to set up and understand, but you may need to come up with (and remember!) a lot of different hot key combinations with ever more difficult finger contortions.

Level 2 is "give each macro the same hot key, then use the Conflict Palette". That way you only need one hot key combo, then you pick from the palette by mouse/trackpad or by typing the highlighted "next unique character" until you you narrow the list to only one macro.

@griffman's Level 3 solution lets you use whatever single-character, unmodified, hot key for you macros because the macros are only "active" and available when the palette is on screen. It's similar to the Conflict Palette method with the advantages that a) once the palette is up you only need a single keystroke to trigger the macro, and b) you can make that keystroke meaningful without having to jump through hoops with your macro names. The "only available for one action, when the palette is on screen" is very important here -- imagine if, when editing an email, you could no longer type the letter "O" because each time you did it triggered a macro instead!

Starting from zero with KM can be frustrating. Some people grok the underlying concepts immediately, some don't. Have another skim of the manual so you know where to find things, and bookmark it so it's always to hand as you write your first macro. Don't get overwhelmed by all the actions and their options, you don't need to learn them all because the wiki is searchable and very detailed -- many items in the Editor also link to their wiki entries via their ? button.

Most of all -- don't spend days, or even hours, getting frustrated! If you bash your head against something for more than 5 minutes, post here and someone is sure to help. Which brings me to:

Please understand that this is done out of love. It's nearly always because the person making the suggestion has tried to do what you are doing and found that, for them, they had to use their posted solution instead. Relevant example here -- using the "Select Menu..." action won't work reliably if you have more than one item with the same name at the same menu level, so you have to reach for AppleScript if that's the case.

Other posters are always working with incomplete information about your situation, assumptions have to be made, and it's all too easy to get those wrong...

1 Like

And the only reason I did this is because of the way Mail Act-On seems to work, via some single-key presses. And especially with something like filing messages, where you might have a dozen mailboxes you regularly file in, I was thinking a palette with single-key keystrokes would be much simpler to use than memorizing (and giving up for any other use) a dozen hotkey combos.

A reasonable analogy may be to consider Keyboard Maestro like the Mac's greatest supermarket: It contains all of the ingredients needed to create almost anything you can imagine. However, what it is not is a cookbook: It doesn't contain the recipes to create all of those things.

A good way to approach new macro creation is to consider what you would do manually, in the app you're trying to automate, to accomplish the task you want to get done. In the case of filing Mail messages, that means ignoring Mail Act-On, because you wouldn't be using that via Keyboard Maestro.

When I first started writing macros, I would draw out a little requirements document for each macro, explaining to myself what the process looked like manually. In this case, it might've looked something like this:

  1. Make sure Mail is active and frontmost.
  2. Select the messages to be filed.
  3. Select Message > Move To > [target mailbox]

Then I would head into Keyboard Maestro and create a new macro. When I first started, more than likely I'd write the macro in the Global Macro Group group; as I gained experience, I learned about using my own macro groups, set to only be available in the application I wanted to work with.

With the above simple outline, after creating a new macro, I'd start looking for commands that let me do those things. A useful command in Keyboard Maestro to help with this can be found in the Edit menu, Edit → Insert Action → By Name (or Control-Command-A). This brings up a prompt box that searches the entire Keyboard Maestro "supermarket" based on what you type:

The Help link at the bottom is critically important for learning about Keyboard Maestro, because its help is context sensitive. Select Help on the selected action, and the relevant help page opens in your browser.

This context sensitive help can also be found in the Gear menu for every action:

image

I spent (and still spend!) a lot of time with Keyboard Maestro's help pages; they may be a bit obtuse in some sections, but you can ask any help-related questions here in the forums, and more than likely, some of us have spent enough time there to be able to help.

So in short, you've bought into the greatest supermarket available for macOS, and you can write recipes that will help you automate almost anything. But those recipes aren't included in the supermarket; Keyboard Maestro's help files and these forums can help you write those recipes...and the more of them you write, the easier they become to write.

-rob.

Thank you all for your patience and forbearance.

It has actually been gratifying that the responses have been prompt and detailed, and that gives me further confidence that I did in fact make a good choice, and I'll be paying for the software when my trial expires.

Petulant? I accept the feedback and will endeavor to be more charming in the future. It should be easier for me now that I have at least crossed the first threshold.

I will come back to these last messages after I've had a chance to upgrade my system (finally!) to the new OS.

If nothing else, this wandering tour through the recess of Keyboard Maestro has demonstrated that it does have immense capabilities, and I'll be exploring them once I get settled into Sonoma.

Again, sincere thanks,

--PS

2 Likes

Hang in there, KM is powerful and but can feel overwhelming at first blush. Once it clicks the possibilities open wide up. Now that you’ve got your toes wet I bet you’ll find many other areas where you can make large and small changes to how you use the computer.

1 Like

I know I'm a bit late in the game but would like to share my piece of work.

I believe it is more powerful than the other solutions.

It has the following features:

  • Unlimited number of filters
  • Can filter on email address, subject or both
  • Stores filter definitions in a sqlite database.
  • Filters can use 'starts with', 'ends with', 'equals', or even regular expressions for matching.

When running a filter it will search for a match in the database. When found it will be executed and the selected email message will be moved to its destination.

If not found it will prompt with two dialogs. The first dialog will ask for the target mailbox and the second dialog will ask for the matching criteria.

It is unfortunate that these two dialogs cannot be combined. The "Prompt for User Input" action cannot do a search in a long list of values.

After validation the new filter is stored in the database for future use.

Please give me feedback. Also this code is relatively new so if you run into problems let me know and I will see if I can help.

mail-act-on.kmmacros (392.9 KB)

1 Like

I'm glad to see that others are finding some merit in this thread.

For my part, I am happy with KM now that I have gotten it to go through the little hoops I needed it for, and the suggestions here have given me a much better idea of its capabilities.

I suspect there will be more I will try in the near future.

Thanks,

--PS

2 Likes

I think you may have typos in naming some of your variables, causing the macro to fail for me.

For example:

and

Can you share some of the error messages?

There are two variables one being the folder and one being the database. The database is the concatenation of the folder and name.

So the create folder should just create the folder. The sqlite3 is running against the database.

Sure:

2024-07-03 13:19:41 Action 14982195 failed: New Folder failed because destination is not a full path (null)
2024-07-03 13:19:41 New Folder failed because destination is not a full path (null) in macro “mail-act-on” (while executing Create New Folder “%Variable%Email_db_folder%”).
2024-07-03 13:19:41 Action 14982198 failed: Write File failed to write file to /Users/xxx/.email_db/script.sql with error Error Domain=NSCocoaErrorDomain Code=4 "The file “script.sql” doesn’t exist." UserInfo={NSURL=file:///Users/xxx/.email_db/script.sql, NSUnderlyingError=0x600000bf5560 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2024-07-03 13:19:41 Write File failed to write file to /Users/xxx/.email_db/script.sql with error Error Domain=NSCocoaErrorDomain Code=4 "The file “script.sql” doesn’t exist." UserInfo={NSURL=file:///Users/xxx/.email_db/script.sql, NSUnderlyingError=0x600000bf5560 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} in macro “mail-act-on” (while executing Write create table script to script file).
2024-07-03 13:19:41 Action 14982199 failed: Execute a Shell Script failed with script error: text-script: line 1: $KMVAR_MAO_script_file: ambiguous redirect
2024-07-03 13:19:41 Execute a Shell Script failed with script error: text-script: line 1: $KMVAR_MAO_script_file: ambiguous redirect. Macro “mail-act-on” cancelled (while executing Create the table).

I didn't dive too deep into it, so I could be wrong, but I thought I saw typos related to using one or two underscores (MAO__db vs MAO_db) and a few others. For example, there is an action looking for %Variable%Email_db_folder% but I don't see that variable anywhere. I do see MAO__db_folder so I thought that was a typo as shown in the screenshot above.

Thanks I will look into this.

You were spot-on with the underscores. I retested the software after removing all variables that start with MAO. Lessor learn here.

Here is a new version.
mail-act-on V0.2.kmmacros (392.8 KB)

Hi there!

Your project is a good way to learn about KM. So, I don‘t want to spoil this.

But as an alternative to a macro, you could use Favorites in Mail. If you right-click on a mailbox in your sidebar you can save this specific mailbox as a favorite.

And here comes the fun part: you can open the first mailbox in your list of favorites with ⌘1. The second favorite with ⌘2 and so on.

Moving any selected mail to your first favorite mailbox works by pressing ⌃⌘1 on your keyboard. ⌃⌘2 for your second favorited mailbox and so on.

Hope this helps.
Ralph