Skip to content

Commit

Permalink
v.0.0.1
Browse files Browse the repository at this point in the history
Initial release
  • Loading branch information
ldebritto committed Feb 3, 2022
1 parent 2ad1c63 commit 251514b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
Binary file added Mail Message Sorter.alfredworkflow
Binary file not shown.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
# alfred-mail-sorter
Moves currently selected message in Mail.app to a folder selected via Alfred interface
Moves currently selected message in Mail.app to a folder selected via Alfred interface.

## Usage
With a selected message in Mail:

1. Press `⌃M` (default shortcut)
2. Typing `sort`command into Alfred
3. Type the name of the folder (or part of it) until you see the desired folder selected
4. Hit return/enter

## How does it work
1. Uses AppleScript to enumerate folder names for the selected account and feed a *Script Filter* on the Alfred Workflow;
2. Selecting the desired folder will feed the next action with the name of such folder;
3. A seccond AppleScript will use the name of the folder to select the corresponding "Move to…" item in menubar.

# Known Issues

## Doesn't work with folders named the same accross different accounts

Will not work for folders in different accounts that share the same name (there's an AppleScript workaround for that move command, but it does not work fine with Gmail accounts, this is why I've preffered this method).

To work around this limitation, I suggest adding a capital letter to the end of the name of the chosen folder, identifying the account. As in:
- Gmail "Later" will be renamed to "Later G"
- Work "Later" will be renamed to "Later W"

This way one can easily surface the correct folder for each account by typing "Later".

# Credits
- Icon from the Noun Project, under the Creative Commons license.
https://thenounproject.com/icon/move-folder-545831/
31 changes: 31 additions & 0 deletions enumerate mail folders.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set accountList to {}
set mailboxList to {}

tell application "Mail"

try
if selection is {} then error
set theMessage to the first item of (selection as list)
set currentMailbox to mailbox of theMessage
set theAccount to the account of currentMailbox
end try

set allAccountMailboxes to every mailbox of theAccount

repeat with eachMailbox in allAccountMailboxes

set thisReccord to {uid:(name of eachMailbox) & "-" & (name of theAccount), title:(name of eachMailbox), subtitle:(name of theAccount), arg:[(name of eachMailbox), (name of theAccount)], valid:true, match:(name of eachMailbox)}
set the end of mailboxList to thisReccord

end repeat

set |items| to {|items|:mailboxList}
end tell

tell application "JSON Helper"
set mailboxList to make JSON from ¬
|items| with pretty printing
end tell
9 changes: 9 additions & 0 deletions move command
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
on run argv
set theMailbox to item 1 of argv
activate application "Mail"
tell application "System Events"
tell process "Mail"
click menu item theMailbox of menu 1 of menu item 18 of menu 1 of menu bar item 7 of menu bar 1
end tell
end tell
end run

0 comments on commit 251514b

Please sign in to comment.