Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
A few of us were chatting in this thread about Apple dropping support for plugins in Mail for macOS Sonoma. We have a possible solution for folks who were using Mail Act-On to assign keyboard shortcuts to move messages into designated folders. It uses a combination of Automator, Applescript, and Keyboard Shortcuts.

I've tested this in macOS Ventura and it's pretty easy to set up and works well but I don't have access to 'Sonoma to see if it works there and how the setup might be different.

Once you have this feature you can't live without it so I'd be interested to see what others think.

Here is a screencast walk-through:


This is the Applescript referenced:

AppleScript:
(* "mail account name in quotes" should match the human-readable name for the mail account that you want to copy mail into *)
(* example myaccount name might be "Gmail" or "Work" *)
(* if your target folder is on the top-level of your account, change "target folder name in quotes" to the folder name eg: "Newsletters" *)
(* if your target folder is nested, use forward slashes to traverse the hierarchy eg: "Receipts/2024" *)

tell application "Mail"
 
    set myaccount to "mail account name in quotes"
    set folderlist to name of mailboxes in account myaccount
    set theMessages to selection
 
    repeat with eachMessage in theMessages
        set mailbox of eachMessage to mailbox "target folder name in quotes" of account myaccount
    end repeat
 
end tell
 

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
Do you know if MsgFiler can be configured to bypass the pop-up menu and simply move messages directly to folders using keyboard shortcuts? At the very least this does look excellent for those looking for a GMail-like experience with the smallest amount of setup. 👍🏻
 

MikeDr206

macrumors 6502a
Oct 9, 2021
517
368
Do you know if MsgFiler can be configured to bypass the pop-up menu and simply move messages directly to folders using keyboard shortcuts? At the very least this does look excellent for those looking for a GMail-like experience with the smallest amount of setup. 👍🏻

Unfortunately, it would be a two-step process. First press Command-9 to call up the menu, and the press fn-X to automatically move the selected mail to favorite folder X, where X is a number between 0 and 9.

Per the manual (https://msgfiler.com/support/docs/#favorites),


While in the mailbox results list, you can use the number keys, 0-9, to quickly select between the first ten mailboxes.

Pressing a number key while holding down the Fn key or command-option-control will instantly file your message into the desired mailbox. Assign numbers to your favorite mailboxes for even faster filing.
 
  • Like
Reactions: strayduck

desertman

macrumors 6502a
Jul 14, 2008
698
37
Arizona, USA
I use MsgFiler, and it still works with Sonoma.
I also use MsgFiler and stayed with Ventura because I had read in several places that MsgFiler no longer works with Sonoma (because Apple, in its infinite wisdom, disabled third-party mail plugins). After reading your post, I found two more places that confirmed that MsgFiler does indeed work with Sonoma. That's great to hear!

What kind of Mac do you have? Intel or M1/M2/M3?
 
Last edited:
  • Like
Reactions: strayduck

MikeDr206

macrumors 6502a
Oct 9, 2021
517
368
I also use MsgFiler and stayed with Ventura because I had read in several places that MsgFiler no longer works with Sonoma (because Apple, in its infinite wisdom, disabled third-party mail plugins). After reading your post, I found two more places that confirmed that MsgFiler does indeed work with Sonoma. That's great to hear!

What kind of Mac do you have? Intel or M1/M2/M3?

I have a MBA M1 and a Mini M2 Pro.
 

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
UPDATE: Circumstances dictated that I get my Apple silicon a few months earlier than I had planned, so I became my own Sonoma tester.

I am happy to report that the AppleScript+Keyboard Shortcuts work perfectly (not surprising) and the setup process is identical to Ventura.

I'm now happily filing messages into a dozen folders at lightning speed. ⚡️📨🥳
 
  • Like
Reactions: Apathist

Apathist

macrumors member
Jan 29, 2024
31
29
I'm now happily filing messages into a dozen folders at lightning speed. ⚡️📨🥳

Thanks for pursuing this!

A useful tip, especially if you're repetitively filtering into a relatively limited set of target folders (remembering a dozen Mail-specific keyboard shortcuts would likely exceed my capacity, sad to say).

-----

Irrelevant exit comment: The command "set folderlist ..." seems like it could be deleted.
 

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
Irrelevant exit comment: The command "set folderlist ..." seems like it could be deleted.

Since I was in here doing some further testing I tried this out and you are correct!

I also noticed that after filing messages, my inbox reverts to a state where no messages are highlighted. To save the extra keystroke (and also avoid a very deep rabbit hole of determining what the "next" message in an "All Inboxes" situation I added a second AppleScript to run after each mail filing action:


AppleScript:
(* only System Events can send keystrokes *)
(* we send a "down arrow" keystroke after filing mail to select the first message in the inbox *)

tell application "System Events"

    key code 125

end tell

It's a little fiddly to set up in terms of getting past permissions warnings, but once this is settled and working I'm going to write up a full article on it including references and credits.
 

Attachments

  • down-arrow.png
    down-arrow.png
    99.9 KB · Views: 76

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
UPDATE: I've run into a peculiar bug where moved messages sometimes reappear in my inbox.

IMAP and Exchange accounts work properly:
(1) Run move script via keyboard shortcut
(2) Confirm that message is in the destination folder
(3) Confirm that message is no longer in Apple Mail Inbox
(4) Log into webmail and confirm the message is gone from the SERVER Inbox folder
(5) All smiles


With GMail (Personal and Business)
(1) Run move script via keyboard shortcut
(2) Confirm that message is in the destination folder
(3) Confirm that message is no longer in Apple Mail Inbox
(4) BAD: Log into webmail. THE MESSAGE IS STILL ON SERVER INBOX
(5) BAD: Some minutes later, the message reappears in Apple Mail's Inbox (but not as "new/unread")
(6) GOOD: The original moved copy of the message is also still in the destination folder


Since I'm "Inbox Zero" (thus the keyboard shortcuts) I can use a REALLY UGLY workaround by creating a straight-up Apple Mail "rule" to move all incoming GMail into one of my IMAP Inboxes, but I'd obviously like for Google to see my command as "move" instead of "copy" (or "delete" since I'm moving to a folder in another account)

I've tried switching the AppleScript from:

AppleScript:
set mailbox of eachMessage to mailbox "2024 Receipts" of account myaccount

to:

AppleScript:
move eachMessage to mailbox "2024 Receipts" of account myaccount

...but the behavior is the same.

I've also deleted my GMail account and re-added to Apple mail. The behavior is the same.

I've also restarted my computer (just in case). The behavior is the same.

I'm not sure how to determine whose bug this is, Apple's (mail), Google's (sync support), or mine?
 

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
UPDATE: Sometimes you need to type out the problem publicly and read it to see that you've answered your own question. I've updated the script to:

(1) change "set/move" to "copy", followed by "delete"

(2) removed the second AppleScript for the "down arrow" action because the act of deleting a message automatically selects the next one in the list.

A couple of forced tests worked (including one with multiple messages selected) but I'll be scrutinizing this a bit more over the next week. Here is where the full script is at currently:

AppleScript:
(* Mail Mover 1.3 *)

(* "mail account name in quotes" should match the human-readable name for the mail account that you want to copy mail into *)

(* example myaccount name might be "Gmail" or "Work" *)

(* if your target folder is on the top-level of your account, change "target folder name in quotes" to the folder name eg: "Newsletters" *)

(* if your target folder is nested, use forward slashes to traverse the hierarchy eg: "Receipts/2024" *)

tell application "Mail"
   
    set myaccount to "mail account name in quotes"
    set theMessages to selection
   
    repeat with eachMessage in theMessages
        copy eachMessage to mailbox "target folder name in quotes" of account myaccount
        delete eachMessage
    end repeat
   
end tell
 

Snugs214

macrumors newbie
May 27, 2024
1
0
Thank you for this @strayduck ! I've held off on upgrading to Sonoma specifically because of the loss of the keyboard message filing shortcuts I had configured through the SmallCubed plugin. Your script and video walk-through are working perfectly for me (pre-upgrade, but I can't see why it wont' work once I do the OS upgrade). I definitely appreciate the solution and easy walk-through you provided.
 

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
Guys, based on a tip from @jhollington we can actually remove Automator from this process entirely, which avoids the special permission setup and greatly speeds the process of moving messages.

The Automator version will still continue to work if you want to enhance it with a folder selector or other features, but if you're just looking to blast messages quickly into folders all you have to do is go to:

System Settings -> Keyboard -> Keyboard Shortcuts -> App Shortcuts

... and assign keyboard shortcuts to Mail using the following format:


Code:
Message->Move to->{target folder name}
keyboard-rules-only.png

These are the full rules:
  • Keyboard shortcuts are assigned to the Mail app
  • Keyboard shortcuts are formatted as: Message->Move to->{folder name}
  • {folder name} is typed as-is. No quotes are needed if multiple words
  • {folder name} must be unique among all folders in all accounts everywhere. This means that if you have multiple folders for the year eg: "2024" you need to name them to be specific eg: "2024 Receipts", "2024 Newsletters", etc.
  • {folder name} does not contain ANY nesting information
    • Do not include "On My Mac" if filing locally
    • Do not include account name if targeting a remote IMAP account eg "Gmail"
    • Do not include any parent folders. For example, if you are targeting: Receipts->2024 Receipts, only enter 2024 Receipts as your target
The missing piece from before was the "->" that allowed us to poke a menu directly in the Mail App.

Thanks for your patience as we worked all of this out.
 

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
(another) UPDATE (like a crazy person): After my Mail app restarted the abbreviated workflow from post #14 above stopped working so I've reverted to the full Automator solution which is the primary subject of this thread.

Not sure what went sideways. If anyone discovers anything, do post it here but for now I need to stick to something that works, even if slightly less performant.
 

fisherking

macrumors G4
Jul 16, 2010
11,255
5,565
ny somewhere
i miss apps like 'mailunreadmenu' (there were others as well).

i'd like an unread mail count in the menubar. anyone know of a way to do that, or an app that would work in sonoma?
 

strayduck

macrumors member
Original poster
Feb 15, 2015
41
13
New York
Update: Thanks in part to having keyboard shortcuts, I recently got back down to Inbox Zero (hurray!). In doing so I see that script #2 of 2 is kicking back an error because it tries to select the first message in what is now an empty index. (Boo!) I've updated the script at GITHub and am posting it here for posterity.

The change is that the script now checks to see if there are any messages left before trying to select one.

AppleScript:
(* script 2 of 2 *)
(* Count messages in inbox. *)
(* If >0, then select first message in current view *)
tell application "System Events"
    tell process "Mail"
        set rowCount to count of visible rows of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
        if rowCount > 0 then
            select row 1 of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
        end if
    end tell
end tell
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.