elliottcable / jello

Mac OS X pasteboard watcher and copy/paste manager

This URL has Read+Write access

jello /
name age message
file .gitignore Mon Sep 29 22:19:50 -0700 2008 Preparing for release - added a rakefile, so I ... [elliottcable]
file .manifest Mon Oct 13 22:58:37 -0700 2008 * Added error toleration for moulds, now a brok... [elliottcable]
file README.markdown Tue Dec 23 22:14:36 -0800 2008 Added a launchd plist creator, courtesy of Laun... [elliottcable]
file Rakefile.rb Thu Mar 05 00:09:22 -0800 2009 Fixed some stylistic concerns regarding whitesp... [elliottcable]
directory bin/ Thu Mar 05 03:47:03 -0800 2009 Added some safety against missing mould files [elliottcable]
file jello.gemspec Thu Mar 05 00:09:23 -0800 2009 Version bump to 7! Mostly to pull in the sexy n... [elliottcable]
directory lib/ Thu Mar 05 00:09:23 -0800 2009 Version bump to 7! Mostly to pull in the sexy n... [elliottcable]
directory moulds/ Thu Mar 05 00:09:22 -0800 2009 Fixed some stylistic concerns regarding whitesp... [elliottcable]
directory spec/ Thu Mar 05 00:09:22 -0800 2009 Fixed some stylistic concerns regarding whitesp... [elliottcable]
README.markdown

Jello

Because everybody likes "paste & jello" sandwiches, right? I know I did when I was a kid.

Jello is a simple library to watch the OS X pasteboard and do something on every paste.

require 'jello'

Jello::Mould.new do |paste|
  system "say 'You pasted #{paste}'"
end

Jello.start!

For example, to watch for URLs copied, and then shorten the URL and replace the long URL with the shortened one, write a short mould like the following:

require 'open-uri'
require 'jello'

Jello::Mould.new do |paste|

  if paste =~ %r{^http://.*}
    uri = $&
    uri.gsub! /#/, '%23'
    unless uri =~ %r{^http://bit.ly}
      shortener = 'http://bit.ly/api?url=' + uri
      open(shortener).gets.chomp
    else
      nil
    end
  end

end

Jello.start! :verbose => true

Moulds can even be stacked:

require 'jello'

Jello::Mould.new do |paste|
  paste += '123'
end

Jello::Mould.new do |paste|
  paste += '456'
end

Jello.start! :verbose => true

Jello also provides a binary - if you have some moulds you use often, you can throw them in your ~/.jello/ folder (as .rb files), and then run jello with them:

# Assuming ~/.jello/ contains foo.rb, bar.rb, and gaz/{one,two}.rb
$ jello foo bar gaz
# Now foo.rb, bar.rb, one.rb, and two.rb would be executed on incoming
# pastes

You can also use pasteboards other than the general one (see man pbcopy for more information about this):

require 'jello'

Jello::Mould.new do |paste|
  paste.gsub! /abc/, 'def'
end

Jello.start!

Finally, you can create a Jello property list for launchd that will keep jello running all the time, even after you restart. Just run rake launchd from the Jello distribution directory. (This requires that you install the LaunchDoctor gem first!)