Skip to content

Instantly share code, notes, and snippets.

@russellbeattie
Created June 1, 2016 01:11
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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.
#!/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