diff --git a/Mail Message Sorter.alfredworkflow b/Mail Message Sorter.alfredworkflow new file mode 100644 index 0000000..bbea4ab Binary files /dev/null and b/Mail Message Sorter.alfredworkflow differ diff --git a/README.md b/README.md index 0d33e81..2579102 100644 --- a/README.md +++ b/README.md @@ -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/ \ No newline at end of file diff --git a/enumerate mail folders.scpt b/enumerate mail folders.scpt new file mode 100644 index 0000000..23597ab --- /dev/null +++ b/enumerate mail folders.scpt @@ -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 \ No newline at end of file diff --git a/move command b/move command new file mode 100644 index 0000000..16fc8f5 --- /dev/null +++ b/move command @@ -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 \ No newline at end of file