Skip to content

Instantly share code, notes, and snippets.

@morygonzalez
Forked from negipo/script
Last active October 19, 2015 03:41
Show Gist options
  • Save morygonzalez/2054855 to your computer and use it in GitHub Desktop.
Save morygonzalez/2054855 to your computer and use it in GitHub Desktop.
/Applications/Gyazo.app/Contents/Resources/script
#!/usr/bin/env ruby
require 'fileutils'
require 'digest/md5'
def main
user = IO.popen("whoami", "r+").gets.chomp
file = "/Users/#{user}/Dropbox/Public/gyazo/#{Digest::MD5.hexdigest(Time.now.to_f.to_s)}.png"
url = 'https://dl.dropboxusercontent.com/u/2611378/gyazo/' + File.basename(file)
FileUtils.mkdir_p File.dirname(file)
imagefile = ARGV[1]
if imagefile && File.exists?(imagefile)
system "sips -s format png \"#{imagefile}\" --out \"#{file}\""
else
system "screencapture -i \"#{file}\""
end
if File.exist?(file) then
system "sips -d profile --deleteColorManagementProperties \"#{file}\""
end
wait_for_upload(url)
system "echo -n #{url} | pbcopy"
system "open #{url}"
end
def wait_for_upload(url)
until(`curl -I -X GET '#{url}'`.match(/200 OK/)) do
sleep 1
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment