Skip to content

Instantly share code, notes, and snippets.

@duff
Created October 9, 2012 16:53
Show Gist options
  • Save duff/3860010 to your computer and use it in GitHub Desktop.
Save duff/3860010 to your computer and use it in GitHub Desktop.
Skitch Image Url Grabber
In the Skitch app, they have a keyboard shortcut to publish/share an image. It puts the url in the clipboard.
This script gets the *real* image url from that page and puts the result in the clipboard.
Also cleans up the url to not use https and grab the jpg rather than png. This all helps with Hipchat.
The end result is that I can hit 2 keyboard shorcuts to get the real url in the clipboard which can then be
pasted into Hipchat.
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
clipboard = IO.popen('pbpaste', 'r+').read
def cleanup_img_src(img_src)
img_src.to_s.sub(/https/, 'http').sub(/\.png/, ".jpg")
end
begin
doc = Nokogiri::HTML(open(clipboard))
rescue
puts "Is there a skitch url in the clipboard? We need one there to do anything."
exit 0
end
image_url = cleanup_img_src(doc.xpath("//img/@src"))
if image_url == ''
puts "No dice. Tried to get an image but couldn't using the url in the clipboard"
exit 0
end
puts "Got the image!\n#{image_url}"
IO.popen('pbcopy', 'w').print image_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment