-
-
Save negipo/1046574 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 | |
file = "/Users/po/Dropbox/Public/g/#{Digest::MD5.hexdigest(Time.now.to_f.to_s)}.png" | |
url = 'https://dl.dropboxusercontent.com/u/275354/g/' + File.basename(file) | |
FileUtils.mkdir_p File.dirname(file) | |
system "screencapture -i \"#{file}\"" | |
if File.exist?(file) then | |
system "sips -d profile --deleteColorManagementProperties \"#{file}\"" | |
dpiWidth = `sips -g dpiWidth "#{file}" | awk '/:/ {print $2}'` | |
dpiHeight = `sips -g dpiHeight "#{file}" | awk '/:/ {print $2}'` | |
pixelWidth = `sips -g pixelWidth "#{file}" | awk '/:/ {print $2}'` | |
pixelHeight = `sips -g pixelHeight "#{file}" | awk '/:/ {print $2}'` | |
if (dpiWidth.to_f > 72.0 and dpiHeight.to_f > 72.0) then | |
width = pixelWidth.to_f * 72.0 / dpiWidth.to_f | |
height = pixelHeight.to_f* 72.0 / dpiHeight.to_f | |
system "sips -s dpiWidth 72 -s dpiHeight 72 -z #{height} #{width} \"#{file}\"" | |
end | |
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