我正在尝试通过 Ruby 的 ScriptingBridge 获取 OS X 上正在运行的进程的列表。
一切正常,除了获取进程ID。问题似乎是调用 Ruby 的内部 Object#id 属性而不是 SystemEvents.process.id 选择器。
这是我当前的示例代码:
#!/usr/bin/env ruby
# Lists all active processes
require 'osx/cocoa'
include OSX
OSX.require_framework 'ScriptingBridge'
app = SBApplication.applicationWithBundleIdentifier_("com.apple.SystemEvents")
procs = app.processes
procs.each do |x|
puts "Process No. #{x.id}: #{x.name}"
end
这是(部分)它的输出:
merlin:mw ~/> /Users/mw/Projekte/Ruby/winlist.rb
/Users/mw/Projekte/Python/winlist.rb:13: warning: Object#id will be deprecated; use Object#object_id
Process No. 2275604960: loginwindow
/Users/mw/Projekte/Python/winlist.rb:13: warning: Object#id will be deprecated; use Object#object_id
Process No. 2275603460: talagent
/Users/mw/Projekte/Python/winlist.rb:13: warning: Object#id will be deprecated; use Object#object_id
Process No. 2275600720: Dock
[... snipped list of all my processes ...]
如何确保调用 ScriptingBridge,而不是 Object#id?