diff --git a/Mail Message Sorter.alfredworkflow b/Mail Message Sorter.alfredworkflow index bbea4ab..6275dad 100644 Binary files a/Mail Message Sorter.alfredworkflow and b/Mail Message Sorter.alfredworkflow differ diff --git a/README.md b/README.md index d238835..56cf3ab 100644 --- a/README.md +++ b/README.md @@ -13,20 +13,17 @@ With a selected message in Mail: ## 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. +2. Selecting the desired folder will feed the next action with the name of such folder and the name of its account; +3. A seccond AppleScript will use this info to issue a move command to each of the selected messages. # Known Issues -## Doesn't work with folders named the same accross different accounts +## Does not work with Gmail accounts +For some reason I suspect is related do the way Mail handles Gmail's proprietary protocol, I guess the move command is not properly held. -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). +Previously, I used a move commant based on a System Events requisition to click on the corresponding "Move to…" command. Gmail worked fine this way. That, however, needed folders to have different names on each account and, also, will require retooling yearly (every time macOS updates), since the position of the menus could change. Different languages were also a con… -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". +Current approach does work properly with Exchange and iCloud accounts. Others may work as well. # Credits - Icon from the Noun Project, under the Creative Commons license. diff --git a/enumerate mail folders.scpt b/enumerate folders for the account of selected message.applescript similarity index 92% rename from enumerate mail folders.scpt rename to enumerate folders for the account of selected message.applescript index 1d72086..163d999 100644 --- a/enumerate mail folders.scpt +++ b/enumerate folders for the account of selected message.applescript @@ -1,10 +1,12 @@ 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) @@ -25,6 +27,6 @@ tell application "Mail" end tell tell application "JSON Helper" - set mailboxList to make JSON from ¬ + set mailboxList to make JSON from  |items| with pretty printing -end tell +end tell \ No newline at end of file diff --git a/move command.applescript b/move command.applescript new file mode 100644 index 0000000..ce28d9a --- /dev/null +++ b/move command.applescript @@ -0,0 +1,15 @@ +on run argv + tell application "Mail" + try + set mailboxName to item 1 of argv + set theAccount to item 2 of argv + if selection is {} then error + set messageList to (selection as list) + repeat with theMessage in messageList + -- set theMessage to the first item of (selection as list) + set theMailbox to mailbox mailboxName of account theAccount + set mailbox of theMessage to theMailbox + end repeat + end try + end tell +end run \ No newline at end of file diff --git a/move command.scpt b/move command.scpt deleted file mode 100644 index 09b643d..0000000 --- a/move command.scpt +++ /dev/null @@ -1,9 +0,0 @@ -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