Skip to content

Instantly share code, notes, and snippets.

@negipo
Forked from youpy/script
Last active September 26, 2015 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save negipo/1046574 to your computer and use it in GitHub Desktop.
Save negipo/1046574 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
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