Skip to content

Instantly share code, notes, and snippets.

@kaspergrubbe
Created May 13, 2015 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaspergrubbe/3d3229fb1fa51f305c19 to your computer and use it in GitHub Desktop.
Save kaspergrubbe/3d3229fb1fa51f305c19 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
require 'json'
DIRECTORY_NAME = '/Users/kaspergrubbe/Pictures/screenie/'
API_KEY = ''
URL = 'https://cdn.servnice.com/screenie'
unless File.directory?(DIRECTORY_NAME)
FileUtils.mkdir_p(DIRECTORY_NAME)
end
def filename
"screenie_#{Time.now.to_f.to_s.gsub(".", "_")}.png"
end
filepath = DIRECTORY_NAME + filename
`screencapture -o -i #{filepath}`
if File.exists?(filepath)
return_json = `curl -X POST \"#{URL}\" -H \"api-key: #{API_KEY}\" -H \"Content-Type: application/octet-stream\" --data-binary \"@#{filepath}\"`
data = JSON.parse(return_json)
imgurl = URL + "/" + data["uuid"] + ".jpg"
`printf #{imgurl} | pbcopy`
else
`say "nope"`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment