Class: Jello::Pasteboard

Inherits:
Object
  • Object
show all
Defined in:
lib/jello/pasteboard.rb

Constant Summary collapse

General =

A pasteboard that stores general text

new :board => :general
Ruler =

Unknown

new :board => :ruler
Find =

A pasteboard that stores the text used in find dialogues

new :board => :find
Font =

Unknown

new :board => :font

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Pasteboard

This creates a new Pasteboard instance, connected to one of the available Mac OS X pasteboards. You shouldn’t use this directly - use one of the pre-defined constants instead.

Yields:

  • (_self)

Yield Parameters:

See Also:



51
52
53
54
55
56
57
58
59
# File 'lib/jello/pasteboard.rb', line 51

def initialize options = {}
  @board ||= options[:board] || :general
  @format ||= options[:format] || :ascii

  yield self if block_given?
  
  @current = ""
  @last = ""
end

Instance Attribute Details

#boardObject (readonly)

The type of board to connect to. Available are the following:

- :general [default]
- :ruler
- :find
- :font

OS X offers various pasteboards for use, depending on what you want to access. They’re synced across the entire system. More information is available under ‘man pbpaste`.

See Also:



20
21
22
# File 'lib/jello/pasteboard.rb', line 20

def board
  @board
end

#currentObject

Returns the value of attribute current.



42
43
44
# File 'lib/jello/pasteboard.rb', line 42

def current
  @current
end

#formatObject

The type of data to request from the board. Available are the following:

- :ascii [default]
- :rtf  (Rich Text)
- :ps (PostScript)

You’re not guaranteed to receive that type, however - you’ll receive it if it’s available, otherwise you’ll receive the first in the above list that is available. More information is available under ‘man pbpaste`.

See Also:



34
35
36
# File 'lib/jello/pasteboard.rb', line 34

def format
  @format
end

#lastObject

The last paste recognized by the pasteboard. If you modify the contents of the pasteboard, you can save processing time by also updating this property with said contents, preventing an extra loop.



40
41
42
# File 'lib/jello/pasteboard.rb', line 40

def last
  @last
end

Instance Method Details

#getsObject

This method gets the latest paste from the selected pasteboard, of the selected format (if possible - see ‘#format`).

See Also:

  • @board
  • @format


67
68
69
70
71
72
# File 'lib/jello/pasteboard.rb', line 67

def gets
  @last = @current
  command = 'pbpaste'
  command << " -pboard #{@board}" if @board
  @current = %x[#{command}].chomp
end

#puts(something) ⇒ Object

This method puts a new entry into the selected pasteboard. Format is automatically deduced from the headers of your string (see ‘man pbpaste` for more info.)

See Also:

  • @board


80
81
82
83
84
85
86
87
88
# File 'lib/jello/pasteboard.rb', line 80

def puts something
  command = 'pbcopy'
  command << " -pboard #{@board}" if @board
  command << " -Prefer #{@format}" if @format
  out = IO::popen command, 'w+'
  out.print something
  out.close
  something
end