Moving single mail message to folder times out
Hello, I am using the script:
tell application "Mail"
set the_messages to selection
set this_message to item 1 of the_messages
set theSender to sender of this_message
move this_message to mailbox "Trash" of account "Main"
set selected messages of first message viewer to first message of first message viewer
end tell
and I get the "error "Mail got an error: AppleEvent timed out." number -1712"
Without the final "set selected messages" it sometimes works, and sometimes doesn't. When it does, there is no more selection, so I can't run it (or a similar one going to a different folder) without having to use the mouse to select a new message.
Further, I want the set selected messages at the end of the script so I can see which one is next, instead of guessing (my mail has been skipping the first 15 or so messages and giving me the 16th as 'first').
Basically, I just want 6 hot keys Fn+1-6 to move messages to one of 6 different folders.
Can anyone provide any help into what I'm doing wrong?
MacBook Pro, OS X Yosemite (10.10.4)