maxdevel (owner)

Fork Of

Revisions

gist: 72377 Download_button fork
public
Public Clone URL: git://gist.github.com/72377.git
Embed All Files: show embed
safaritweet.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/ruby -W0
 
=begin
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!
=end
 
# I don't believe in requiring rubygems itself
#require 'rubygems'
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 = OSA.app('Safari').windows.first.current_tab
 
tweet = "#{tab.name} - #{ShortURL.shorten(tab.url)} "
ARGV.each { |tag| tweet << "##{tag} " }
 
unless tweet.length < 140
  puts "Tweet too long :-("
  exit 1
end
 
# I didn't feel like having my pw in the file
# therefore using poor man's pw protection
twitter_user = '<your user name>'
print 'Enter password: '
STDOUT.flush
system('stty -echo')
twitter_pass = STDIN.gets.chomp
system('stty echo')
puts
 
# post tweet
client = Twitter::Client.new(:login => twitter_user, :password => twitter_pass)
Twitter::Status.create(:text => tweet, :client => client)