Created
June 1, 2016 01:11
-
-
Save russellbeattie/64b73bba760666741857bcf1b10ea8db to your computer and use it in GitHub Desktop.
Searches Apple mail Inbox for your name (if your name is Russ - otherwise change that bit) in the latest message and logs out/marks yellow.
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/env osascript -l JavaScript | |
function run(argv) { | |
var Mail = new Application("Mail"); | |
var inbox = Mail.inbox(); | |
var messages = inbox.messages(); | |
for(var i = 0; i < messages.length; i++){ | |
var message = messages[i]; | |
var text = message.content().toString(); | |
var markers = [ | |
'From: ', | |
'========', | |
'----', | |
'Sent from' | |
]; | |
markers.forEach(function(marker){ | |
var x = text.indexOf(marker) | |
if( x !== -1){ | |
text = text.substr(0, x); | |
} | |
}); | |
var s = text.search(/On.*wrote:/); | |
if( s !== -1){ | |
text = text.substr(0, s); | |
} | |
text = text.trim(); | |
if(text.indexOf(' Russ') !== -1){ | |
console.log('\n\n-----------------------------------------------------------------------------'); | |
console.log(message.dateReceived()); | |
console.log("\x1B[34m" + message.sender() + "\x1B[0m"); | |
console.log("\x1B[32m" + message.subject() + "\x1B[0m"); | |
console.log(''); | |
console.log(text); | |
messages[i].backgroundColor = 'yellow'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment