Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Created July 16, 2011 22:38
Show Gist options
  • Save pdxmph/1086882 to your computer and use it in GitHub Desktop.
Save pdxmph/1086882 to your computer and use it in GitHub Desktop.
Export Frontmost Acorn to PNG, Upload to imgur, Get URL back to clipboard
#!/usr/bin/env ruby
require "rubygems"
require "imgur"
require "appscript"
include Appscript
# get your imgur API key here: http://imgur.com/register/api
imgur_api = "xxxxxxxxxxxxxxxxx"
acorn = app("Acorn")
# [0] is always the frontmost document
img = acorn.documents[0].get
basename = File.basename(img.name.get, '.*')
export_path = "/tmp/#{basename}.png"
img.web_export(:in => export_path, :as => :PNG)
i = Imgur::API.new(imgur_api)
imgur_hash = i.upload_file(export_path)["image_hash"]
img_url = "http://i.imgur.com/#{imgur_hash}"
# copy the path out to the system clipboard
`echo #{img_url}|pbcopy`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment