1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'osx/cocoa'

module OSXApps
  class Base
    def self.all
      OSX::NSWorkspace.sharedWorkspace.launchedApplications.map do |app| 
        {:name => app.allValues[5].to_s, :pid => app.allValues[1].to_i}
      end
    end
  
    def self.find(name)
      all.find { |app| app[:name].match(name) }
    end
  end
end

if $0 == __FILE__
  puts OSXApps.find('Terminal').inspect
end