19 Oct
OSX: Get Frontmost Application
This is how to get the frontmost application (name) in OSX 10.5 Leopard via Applescript and using Ruby with rb-appscript gem… now the code!
Applescript:
Ruby (rb-appscript gem):
1 2 include Appscript 3 4 puts app('System Events').processes.select.map{|p| p.name.get if p.frontmost.get }.compact.first
Full Version: http://pastie.org/295628
#!/usr/bin/env ruby -wKU
include Appscript
#puts app('System Events').processes.frontmost.get
#puts app('System Events').processes.map{ |p| p.get }
puts app('System Events').processes.select.map{|p| p.name.get if p.frontmost.get }.compact.first
# rb-appscript fucking good manual/documentation
# http://appscript.sourceforge.net/rb-appscript/doc/appscript-manual/index.html
#
# Applescript Equivalent:
# tell application "System Events"
# set frontmostApplication to name of the first process whose frontmost is true
# end tell

