Skip to content

Instantly share code, notes, and snippets.

@jpcody
Created September 3, 2011 01:06
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jpcody/1190336 to your computer and use it in GitHub Desktop.
Save jpcody/1190336 to your computer and use it in GitHub Desktop.
Save clipboard contents as private gist using Alfred.app
# It'd be great to get this running via AppleScript and sans Alfred if anyone with more knowledge than me knows how :)
### STEP 1
#!/bin/sh
# Save this file as /bin/rvm_ruby, and do chmod 755 /bin/rvm_ruby
# to give it the proper permissions
# From http://www.aeonscope.net/2011/05/29/connecting-alfred-to-bitly-via-ruby/
if [[ -s ~/.rvm/scripts/rvm ]]; then
. ~/.rvm/scripts/rvm
fi
ruby_version=$1; shift
rvm $ruby_version
exec ruby "$@"
### STEP 2
# Save this file somewhere, anywhere, that you can reference it
require 'curb'
require 'URI'
require 'json'
# This one is tricky. For installation, see https://github.com/dewind/real-growl
# Only do if you want growl notifications of completion
require 'real_growl'
username = "your_github_username"
password = "your_github_password"
gist_post_url = "https://api.github.com/gists"
clipboard_contents = IO.popen( "pbpaste", "r+" ).read
filename = ARGV[0] || "gist"
gist_data = {}
gist_data[:public] ||= false
gist_data[:files] ||= {}
gist_data[:files][filename] ||= {}
gist_data[:files][filename][:content] ||= {}
gist_data[:files][filename][:content] = clipboard_contents
c = Curl::Easy.http_post( gist_post_url, gist_data.to_json ) do |curl|
curl.headers["content-type"] = "application/json"
curl.http_auth_types = :basic
curl.username = username
curl.password = password
end
result = JSON.parse( c.body_str )
url = result["html_url"]
IO.popen( "pbcopy", "r+" ).puts url
# Only do if you want growl notifications of completion
# Save an icon somewhere you can reference it to display with your growl notification.
# I used this one:
# http://cardboardsoftware.com/images/apps/githubissues-icon-trans.png
notification = RealGrowl::Application.new("Gist")
notification.notify( :title => "Gist Uploaded",
:description => "#{url} was copied to your clipboard.",
:priority => 0,
:sticky => false,
:icon => "absolute_path_to_an_image_youd_like_to_use")
### STEP 3
# Set this command up as an Alfred.app extension here: http://d.pr/tT8l
# (Probably required Alfred power pack)
# Use the appropriate rvm_ruby where you've downloaded the requisite gems
rvm_ruby ruby-1.9.2-p290 ~/Library/Scripts/Webdev\ Tasks/upload-gist.rb {query}
### Step 4
# Run it like so:
1. Copy whatever you want to upload to your clipboard
2. Invoke Alfred
3. Type "gist " and the name of the file you'd like to create
4. Hit enter, and a URL will be copied to your clipboard
@phallstrom
Copy link

Not sure how I missed this a couple of days ago, but I just wrote a pure-bash extension for Alfred to do this...

http://pjkh.com/projects/alfredgist/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment