* Added error toleration for moulds, now a broken mould won't crash Jello
[jello.git] / README.markdown
blob389183e8b241af6783e74dec1468ce95ce7f357d
1 Jello
2 =====
4 Because everybody likes "paste & jello" sandwiches, right? I know I did when I
5 was a kid.
7 Jello is a simple library to watch the OS X pasteboard and do something on
8 every paste.
10     require 'jello'
12     Jello::Mould.new do |paste|
13       system "say 'You pasted #{paste}'"
14     end
15     
16     Jello.start!
18 For example, to watch for URLs copied, and then shorten the URL and replace
19 the long URL with the shortened one, write a short mould like the following:
20     
21     require 'open-uri'
22     require 'jello'
23     
24     Jello::Mould.new do |paste|
25     
26       if paste =~ %r{^http://.*}
27         uri = $&
28         uri.gsub! /#/, '%23'
29         unless uri =~ %r{^http://bit.ly}
30           shortener = 'http://bit.ly/api?url=' + uri
31           open(shortener).gets.chomp
32         else
33           nil
34         end
35       end
36       
37     end
38     
39     Jello.start! :verbose => true
40     
41 Moulds can even be stacked:
42     
43     require 'jello'
44     
45     Jello::Mould.new do |paste|
46       paste += '123'
47     end
48     
49     Jello::Mould.new do |paste|
50       paste += '456'
51     end
52     
53     Jello.start! :verbose => true
54     
55 Jello also provides a binary - if you have some moulds you use often, you can
56 throw them in your `~/.jello/` folder (as .rb files), and then run jello with
57 them:
58     
59     # Assuming ~/.jello/ contains foo.rb, bar.rb, and gaz/{one,two}.rb
60     $ jello foo bar gaz
61     # Now foo.rb, bar.rb, one.rb, and two.rb would be executed on incoming
62     # pastes
63     
64 Finally, you can use pasteboards other than the general one (see `man pbcopy`
65 for more information about this):
66     
67     require 'jello'
68     
69     Jello::Mould.new do Jello::Pasteboard::Find |paste|
70       paste.gsub! /abc/, 'def'
71     end
72     
73     Jello.start!