Reversed the order of the moulds in the launchd task (oops!)
[jello.git] / README.markdown
blob9252e937cfd89e32f288b363e484b7cb23191d40
1 Jello
2 =====
3 Because everybody likes "paste & jello" sandwiches, right? I know I did when I
4 was a kid.
6 Jello is a simple library to watch the OS X pasteboard and do something on
7 every paste.
9     require 'jello'
11     Jello::Mould.new do |paste|
12       system "say 'You pasted #{paste}'"
13     end
14     
15     Jello.start!
17 For example, to watch for URLs copied, and then shorten the URL and replace
18 the long URL with the shortened one, write a short mould like the following:
19     
20     require 'open-uri'
21     require 'jello'
22     
23     Jello::Mould.new do |paste|
24     
25       if paste =~ %r{^http://.*}
26         uri = $&
27         uri.gsub! /#/, '%23'
28         unless uri =~ %r{^http://bit.ly}
29           shortener = 'http://bit.ly/api?url=' + uri
30           open(shortener).gets.chomp
31         else
32           nil
33         end
34       end
35       
36     end
37     
38     Jello.start! :verbose => true
39     
40 Moulds can even be stacked:
41     
42     require 'jello'
43     
44     Jello::Mould.new do |paste|
45       paste += '123'
46     end
47     
48     Jello::Mould.new do |paste|
49       paste += '456'
50     end
51     
52     Jello.start! :verbose => true
53     
54 Jello also provides a binary - if you have some moulds you use often, you can
55 throw them in your `~/.jello/` folder (as .rb files), and then run jello with
56 them:
57     
58     # Assuming ~/.jello/ contains foo.rb, bar.rb, and gaz/{one,two}.rb
59     $ jello foo bar gaz
60     # Now foo.rb, bar.rb, one.rb, and two.rb would be executed on incoming
61     # pastes
62     
63 You can also use pasteboards other than the general one (see `man pbcopy` for
64 more information about this):
65     
66     require 'jello'
67     
68     Jello::Mould.new do |paste|
69       paste.gsub! /abc/, 'def'
70     end
71     
72     Jello.start!
73     
74 Finally, you can create a Jello [property list][plist] for [launchd][] that
75 will keep jello running all the time, even after you restart. Just run
76 `rake launchd` from the Jello distribution directory. (This requires that you
77 install the [LaunchDoctor][] gem first!)
79   [launchd]: <http://en.wikipedia.org/wiki/Launchd> "launchd on Wikipedia"
80   [plist]: <http://en.wikipedia.org/wiki/Property_list> "Property list on Wikipedia"
81   [LaunchDoctor]: <http://github.com/elliottcable/launchdr> "elliottcable's launchdr on GitHub"