Guest User

Untitled

a guest
Mar 1st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/usr/bin/ruby -W0
  2.  
  3. =begin
  4. Quick and dirty way to tweet the currently active
  5. Safari tab (title + shortened URL). Hashtags get
  6. passed in as parameters (the hash sign gets added
  7. by the script, so don't do it yourself)
  8.  
  9. Adapt to your needs!
  10. =end
  11.  
  12. # I don't believe in requiring rubygems itself
  13. #require 'rubygems'
  14. require 'highline'
  15. require 'rbosa'
  16. require 'ShortURL'
  17. gem('twitter4r', '0.3.0')
  18. require 'time'
  19. require 'twitter'
  20.  
  21. # OSA stuff to get to the active Safari tab
  22. OSA.utf8_strings = true
  23. tab = OSA.app('Safari').windows.first.current_tab
  24.  
  25. tweet = "#{tab.name} - #{ShortURL.shorten(tab.url)} "
  26. ARGV.each { |tag| tweet << "##{tag} " }
  27.  
  28. unless tweet.length < 140
  29. puts "Tweet too long :-("
  30. exit 1
  31. end
  32.  
  33. # I didn't feel like having my pw in the file
  34. # therefore using highline to ask for it
  35. hl = HighLine.new
  36. twitter_user = 'citizen428'
  37. twitter_pass = hl.ask('Enter password: ') { |q| q.echo = "*" }
  38.  
  39. # post tweet
  40. client = Twitter::Client.new(:login => twitter_user, :password => twitter_pass)
  41. Twitter::Status.create(:text => tweet, :client => client)
Add Comment
Please, Sign In to add comment