19 Oct
mad

mad il 19 October 2008 parla di Altro, Risorse, Rubylation

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:

tell application "System Events"
  set frontmostApplication to name of the first process whose frontmost is true
end tell

Ruby (rb-appscript gem):

    1 require 'appscript'
    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
require 'rubygems'
require 'appscript'
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

rb-appscript gem’s doc & manual

Scrivi un commento