#!/usr/bin/ruby # require 'rubygems' require 'rmagick' require 'tempfile' require 'osx/cocoa' point = OSX::NSEvent.mouseLocation x, y = point.x, point.y tf = Tempfile.new(File.basename($0)) system("screencapture", tf.path) img = Magick::Image.read(tf.path).first pixel = img.get_pixels(x, img.rows - y, 1, 1).first hex = '#%02x%02x%02x' % [:red, :green, :blue].map {|n| pixel.send(n) >> 8 } puts hex open("|pbcopy", "w") {|c| c.print hex }