Created
January 29, 2012 22:46
-
-
Save dzuelke/1701148 to your computer and use it in GitHub Desktop.
AppleScript to import flagged messages from Mail into The Hit List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript | |
on run | |
if not (application "Mail" is running and application "The Hit List" is running) then | |
return | |
end if | |
tell application "Mail" | |
repeat with _account in imap accounts | |
set _inbox to _account's mailbox "INBOX" | |
set _messages to (a reference to (every message of _inbox whose flagged status is true)) | |
-- We must use this workaround, because the reference will self-update once we unflag a message, and that will get us just one of two flagged messages imported | |
-- "Mail got an error: Can’t get item 2 of every message of mailbox..." is the error that applescript reports in this case | |
-- That error was previously suppressed by the try block (which is weird, because it happens in the repeat), so I've commented it out | |
set _msglist to contents of _messages | |
repeat with _message in _msglist | |
--try | |
set theSubject to "Handle @email \"" & subject of _message & "\" from " & sender of _message | |
set theDate to date received of _message | |
set hours of theDate to 0 | |
set minutes of theDate to 0 | |
set seconds of theDate to 0 | |
set theBody to "message:%3c" & (message id of _message) & "%3e" | |
tell application "The Hit List" | |
tell inbox to make new task with properties {title:theSubject, notes:theBody, start date:theDate} | |
end tell | |
-- don't forget to unflag the message :) | |
set flagged status of _message to false | |
--end try | |
end repeat | |
end repeat | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And then have it run every ten minutes, just add it via
crontab -e
: