Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Tweet active Safari tab from command line Web Browsers
I wrote a small Ruby script which allows me to post my currently-active Safari tab on Twitter, including the possibility of adding hashtags. Here's the code, though you you'll find any updates to the script over here, and a bit more detail can be found in this blog post.
#!/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 = 'your_twitter_username'
twitter_pass = hl.ask('Enter password: ') { |q| q.echo = "*" }
# post tweet
client = => twitter_user, :password => twitter_pass)
Twitter::Status.create(:text => tweet, :client => client)
This script uses the RubyOSA bridge for AppleScript support from within Ruby, as well as quite a few other gems (why reinvent the wheel?).

[robg adds: If (like me) you're not a Ruby user, it will take a bit of effort to get this script to work. First, save the above as a text file somewhere on your path and make it executable (chmod a+x tweetsafari.rb). In order to get it working on my machine, I had to uncomment the require 'rubygems' line, and edit the twitter_user = 'your_twitter_username'. I also had to install some of the listed gems from the script. You can do this with the sudo gem install gem_name command. On my machine, I had to install rubyosa, shorturl, and twitter4r in order to get the script to work. Once I had all those bits, though, it worked as described, and tweeted a shortened URL version of my active Safari tab.]
  • Currently 1.44 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (9 votes cast)

Tweet active Safari tab from command line | 1 comments | Create New Account
Click here to return to the 'Tweet active Safari tab from command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Tweet active Safari tab from command line
Authored by: Doc Drang on Mar 09, '09 02:07:22PM
I really think it's better to have a URL-shortening script or service that's separate from Twitter (even though Twitter is my most common use of shortened URLs). A little Googling will find you several solutions that will insert (or put on the clipboard) a shortened version of the frontmost browser window. These are typically launched via Quicksilver, LaunchBar, FastScripts, or utilities like that.

Even more useful are TextExpander snippets that run a script to get and shorten the URL. With one of these, you can just type the abbreviation into whatever Twitter client you use, and out will pop the shortened URL. Mine are here:

I believe Jeff Gamet deserves credit for the idea of using TextExpander to get shortened URLs. His description is here:

Doc Drang

[ Reply to This | # ]