MacOS – How to add all Tweets to the Mountain Lion Notification Center

macosnotificationstwitter

I love the Notification center gesture and would love to be able to glance at my full Twitter stream that way. How can I put all of Twitter into that notification area?

Best Answer

You can get the home timeline from the Twitter API and display tweets using terminal-notifier.

#!/usr/bin/env ruby -KU -rubygems

require 'twitter'
require 'cgi'

Twitter.configure do |config|
  config.consumer_key = ""
  config.consumer_secret = ""
  config.oauth_token = ""
  config.oauth_token_secret = ""
end

timeline = Twitter.home_timeline
first = timeline.first.id
previous = `defaults read me.lri.scripts nctwitter 2> /dev/null`.chomp
minid = previous == "" ? 0 : previous.to_i + 1
`defaults write me.lri.scripts nctwitter #{first}`

timeline.each do |tweet|
  break if tweet.id <= minid
  system("terminal-notifier", "-message", CGI.unescapeHTML(tweet.text),
  "-title", tweet.user.screen_name)
  # system("/usr/local/bin/growlnotify", "-t", tweet.user.screen_name,
  # "-m", CGI.unescapeHTML(tweet.text))
end

growlnotify would stack multiple notifications and not clip the text in long tweets.

The Twitter library can be installed with sudo gem install twitter.

You can run the script every minute by editing the crontab with EDITOR=nano crontab -e and adding a line like * * * * * ~/bin/nctwitter.


A recent update to Tweetbot added an option to send notifications for all tweets: