Apply Multiple Actions to Gmail Messages In Apple Mail

Hello,

I apologize upfront if this is not the appropriate section of the forum to ask this question.

I have a Gmail account and I want to use it through Apple's Mail.app on a Mac.

In the past I used Thunderbird and through the Nostalgy plug-in I was able to assign custom keyboard shortcuts to do things like remove a message from inbox and move it to a certain folder (or in Gmail jargon, remove the "Inbox" label and assign another label). I bought Keyboard Maestro to do the same thing with Mail.app, but I ran into a problem. I set up a few macros similar to the following one:

The macro does move the message to the desired folder (i.e., it assigns the new label), but it does not remove the "Inbox" label.

To remove the "Inbox" label, I would have to "Archive" the message. The problem is that if I either "Archive" or "Move to" the message, it disappears from my view, and I cannot do the second action.

Is there a workaround to do two actions with Keyboard Maestro? I perfectly realize that this is really an issue with Mail.app, and the way in which it interacts with Gmail not with Keyboard Maestro – but I am hoping that automation can provide a solution.

Thank you!

A possible workaround is to periodically go into the specific label in the Gmail web interface, select all messages with that label (luckily there a convenient button to do so) and "Archive" all of them, to remove the "Inbox" label in batch. It's not ideal, it would be nice if I could automate it with Keyboard Maestro.

It still amazes me how lazy and/or negligent Apple is at times...

AppleScript to the rescue.

Select your destination mailbox in Mail and run this AppleScript in Apple's anemic Script Editor app (or better yet Script Debugger).

tell application "Mail"
   tell (some message viewer whose index is 1)
      return item 1 of (get selected mailboxes)
   end tell
end tell

Put the result in the appropriate location in the AppleScript contained in the appended macro.

This works flawlessly for me on Mojave.


Download: Move Selected Messages to Students Mailbox in Gmail Account v1.00.kmmacros (5.9 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

Thank you so much for your help. I followed the instructions (which were very clear even for someone like me who is not familiar with AppleScript).

Unfortunately, it seems to me that the macro does the same thing that my previous macro did.

It does move the message to the desired folder, but it does not remove the "Inbox" label – so it remains in the Inbox folder.

[Just to avoid potential questions: yes, I had disabled my previous macro, so I did run the new macro]

There's a certain amount of kludge required to translate between Google's "big bucket of email organised with tags" and Mail's "mailboxes within a mail account" approach. What we, the users, can do about it might depend on the version of macOS/Mail in use -- what versions are you running?

If nothing else, knowing version numbers will help in replicating the issue.

I am working on Ventura 13.3.1
Mail is 16.0

That's frustrating. As I said – it works fine for me on Mojave.

I'm mistaken about the above. My testing was flawed in that I was moving a non Gmail message from my InBox to the Gmail Students mailbox.

Mail has had notorious problems with Gmail over the years.

This macro works, but unfortunately on Mojave at least the Student's mailbox does not get synced locally.

The moved message shows up in Gmail in a browser but not in Apple Mail.

Hopefully this has been fixed in later versions of macOS, but I wouldn't bet on it.

To test you'll have to do replace the given mailbox references with your own.


Download: Move Selected Messages to Students Mailbox in Gmail Account v2.00.kmmacros (8.4 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

** Note – Mail Act-On from SmallCubed Software does the job exactly right. Selected emails get moved and relabelled properly.

The MailSuite software is expensive, but over the years I've found it well worth the price.