Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
OK! I've done what I can do with the scripts and instructions for now. I've posted the full writeup and code snippets here: https://www.hausinteractive.com/mov...applescript-automator-and-keyboard-shortcuts/

I've posted the scripts to GitHub on the off chance that some AppleScript wizard has some magic regarding what messages to select after mail has been removed from the current inbox: https://github.com/aaronmergerequest/apple-mail-akido. For my use and skill level the "select the first message in the directory" works with my top-down approach to reading mail.

Finally, I'm posting an image of a Red Panda deflecting a message by warping time and space itself.

Thanks everyone for the tips. Without this script, life would have been a whole lot worse.
 

Attachments

  • mail-aikido.png
    mail-aikido.png
    801.9 KB · Views: 94
So, after all the above discussion I had a forehead-slapping moment this morning when I remembered that keyboard shortcuts to move messages into specific folders can already be accomplished in Apple Mail and macOS without any scripting.

The original Applescript I supplied a few pages back was designed to show a list of all folders so that I can select one with typeahead, but for what @strayduck wanted to do — assigning keyboard shortcuts to move messages to specific folders — macOS' built-in keyboard shortcuts feature provides the necessary capabilities as long as you know a hidden trick.

That trick is that you can assign keyboard shortcuts to nested menus by using the "->" symbol. Since all the target folders can already be found under Message->Move to, all you really need to do is open the global keyboard shortcuts in System Preferences or Settings and assign them there...

Screenshot 2024-05-25 at 10.40.24.png
 
  • Like
Reactions: adrianlondon
Thanks @jhollington! The "->" was exactly what I was trying to find back at the start! I probably tried every other combination of >, /, \, etc.

For what I'm doing, though, this technique does not seem to work as one of my levels is the specific IMAP account eg:

Code:
Message->Move to->{account name}->Folder->Nested Folder

Whenever I set up a pure keyboard-shortcut rule without Automator my Mac just beeps at me and doesn't do anything. I've tried the above with and without quotes for multi-word parts of the string.

When I get some time I'll fiddle with it a bit more as skipping Automator not only requires less permissions setup, but it's also a lot faster.
 
  • Like
Reactions: jhollington
IIRC, the ">" did work at one time, but Apple took it out somewhere along the way. I recall using it in Lion or Mountain Lion, but I'm not sure when it went away.

The {account name} part shouldn't be necessary as those aren't nested menus — at least they don't show up that way for me in Sonoma. I just see them as headers above the folders, but I can't remember what it looked like in older macOS releases.

This could be an issue if you had two folders with the same name in different accounts, but I think in that case the keyboard shortcut would just get assigned to the first one. The screenshot I shared above is from my own setup and it works fine with three accounts.

One of the best indications that it's set up properly is that you should see the keyboard shortcuts listed by the folder names when you open the menu.
 
  • Like
Reactions: strayduck
Ok, I did a little more testing and these are the 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
Phew. So all of that said, IT WORKS! And this method is so much faster than processing through Automator.

Thanks for the help. I'll have to go back and update my other posts as this is The Superior Way.
 
  • Like
Reactions: jhollington
UPDATE: After restarting the mail app all the abbreviated keyboard shortcuts stopped working. :-O. They either make the error noise or select the next message in the mailbox rather than moving the selected message. I see some of the keyboard shortcuts still show in the drop-down menu while others don't.

Since this is an integral part of my daily workflow I've had to revert to the full Automator workflow. If I get a chance I may circle back around to troubleshoot further, but it could be a considerable while.
 
UPDATE: After restarting the mail app all the abbreviated keyboard shortcuts stopped working. :-O. They either make the error noise or select the next message in the mailbox rather than moving the selected message. I see some of the keyboard shortcuts still show in the drop-down menu while others don't.
I've encountered this as well... None of my shortcuts are disappearing for me, but they don't work until I open the Message > Move To menu at least once after restarting Mail. I'm guessing it's a bug, but since I usually leave Mail open, that workaround isn't too onerous.

Is there any pattern to the ones that are disappearing? I'm using CMD+SHIFT for all of mine, but it sounds like you might have ones that use single modifier keys, as those modifiers are typically ignored unless they're assigned to keyboard shortcuts, so hitting CTRL+A is the same as just pressing the letter A, which selects the first message with anything starting with that letter (and continuing to type will jump ahead to find messages that match whatever you type).
 
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:
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

@jhollington : It's a good point about the modifier keys and yes, these are all set to use single-key "ctrl" as the modifier. I'm not willing to change the modifier combo so I've instead decided to forge ahead down the path of more resistance so I can have exactly what I want haha.
 
  • Like
Reactions: gwhizkids
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.