Skip to content

Instantly share code, notes, and snippets.

Created February 27, 2009 16:35
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Tweet the currently active Safari tab
#!/usr/bin/ruby -W0
Quick and dirty way to tweet the currently active
Safari tab (title + shortened URL). Hashtags get
passed in as parameters (the hash sign gets added
by the script, so don't do it yourself)
Adapt to your needs!
# I don't believe in requiring rubygems itself
#require 'rubygems'
require 'highline'
require 'rbosa'
require 'ShortURL'
gem('twitter4r', '0.3.0')
require 'time'
require 'twitter'
# OSA stuff to get to the active Safari tab
OSA.utf8_strings = true
tab ='Safari').windows.first.current_tab
tweet = "#{} - #{ShortURL.shorten(tab.url)} "
ARGV.each { |tag| tweet << "##{tag} " }
unless tweet.length < 140
puts "Tweet too long :-("
exit 1
# I didn't feel like having my pw in the file
# therefore using highline to ask for it
hl =
twitter_user = 'citizen428'
twitter_pass = hl.ask('Enter password: ') { |q| q.echo = "*" }
# post tweet
client = => twitter_user, :password => twitter_pass)
Twitter::Status.create(:text => tweet, :client => client)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment