-
-
Save morygonzalez/2054855 to your computer and use it in GitHub Desktop.
/Applications/Gyazo.app/Contents/Resources/script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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