Recently @edrabbit had a great idea: “I want to install a cache of balloons and confetti over my desk for when I achieve inbox zero.”
It was brilliant, so I kludged together the first step: a ruby script that takes an action when you hit inbox zero. Here’s the code, if you want to play along at home. You’ll need to edit your username and password; if you’re on Linux, “gnome-open” is probably the right thing to have there. On OS X, you’ll want “open.” If you’re on Windows, you have your own little set of special problems.
(Note that this program exits 0 when you’ve got inbox zero, and 1 otherwise, so you can easily put it into a shell script. In addition to the exec() command in the script, this could be used to trigger a program that pings an arduino to unlatch a box of balloons and confetti. For my sake, I’ll be thrilled to have “Peanut Butter Jelly Time” pop up when I hit inbox zero.)
#!/usr/bin/env ruby
# You need to add your username and password below!
require 'net/imap'
config = {
'server' => "imap.gmail.com",
'port' => 993,
'username' => "josh.myer@gmail.com",
'password' => "",
'action' => "gnome-open http://bit.ly/pbj_time",
}
imap = Net::IMAP.new(config['server'], config['port'], true)
imap.login(config['username'], config['password'])
imap.select('INBOX')
n = 0
imap.search(["NOT", "DELETED"]).each do |message_id|
n += 1
end
imap.logout()
imap.disconnect()
puts "Your inbox contains #{n} not-deleted messages."
if n == 0
puts "SUCCESS! INBOX ZERO ACHIEVED!"
exec(config['action'])
exit 0 # superfluous, I know
else
exit 1
end
Tags: gmail, Hacks, imap, impossible dreams
Damn you. Now I’m actually tempted to setup an arduino for this!