My first guess is that you’ll want to use the .NET 4.0 build of Eagle to do this (i.e. for compatibility with all the necessary assemblies).
EDIT #1: Slightly revised example that is tested and working on Windows 7
(32-bit) using the .NET Framework 4.0.
EDIT #2: Also, you may want to upgrade to the latest Eagle release (beta 50).
object load UIAutomationClient
object load UIAutomationTypes
object load UIAutomationProvider
set assembly [object load -alias UIAutomationClientsideProviders]
object import System.Windows.Automation
object invoke ClientSettings \
RegisterClientSideProviderAssembly [$assembly GetName]
set prop(pid) [object invoke AutomationElement ProcessIdProperty]
set prop(class) [object invoke AutomationElement ClassNameProperty]
set prop(name) [object invoke AutomationElement NameProperty]
set patt(invoke) [object invoke InvokePattern Pattern]
# optional, close calc.exe
# kill -all calc.exe
set pid [exec calc.exe &]
set pidObject [object invoke -create Int32 Parse $pid]
after 2000; # wait for calc.exe input idle?
set elem(root) [object invoke -alias AutomationElement RootElement]
set cond(1) [object create PropertyCondition $prop(pid) $pidObject]
set elem(pid) [$elem(root) -alias FindFirst Children $cond(1)]
set cond(2) [object create PropertyCondition $prop(class) Button]
if {0} then {
#
# NOTE: Show all the button names within the target window.
#
object foreach -alias elem(this) \
[$elem(pid) -alias FindAll Descendants $cond(2)] {
puts stdout [$elem(this) GetCurrentPropertyValue $prop(name)]
}
}
set cond(3) [object create PropertyCondition $prop(name) 1]
set cond(4) [object create AndCondition $cond(2) $cond(3)]
set elem(btn1) [$elem(pid) -alias FindFirst Descendants $cond(4)]
set cond(5) [object create PropertyCondition $prop(name) Add]
set cond(6) [object create AndCondition $cond(2) $cond(5)]
set elem(btn+) [$elem(pid) -alias FindFirst Descendants $cond(6)]
#
# HACK: Apparently, name for plus button can be different?
#
if {![isNonNullObjectHandle $elem(btn+)]} then {
unset cond(5) cond(6) elem(btn+); # dispose?
set cond(5) [object create PropertyCondition $prop(name) +]
set cond(6) [object create AndCondition $cond(2) $cond(5)]
set elem(btn+) [$elem(pid) -alias FindFirst Descendants $cond(6)]
}
set cond(7) [object create PropertyCondition $prop(name) Equals]
set cond(8) [object create AndCondition $cond(2) $cond(7)]
set elem(btn=) [$elem(pid) -alias FindFirst Descendants $cond(8)]
#
# HACK: Apparently, name for equals button can be different?
#
if {![isNonNullObjectHandle $elem(btn=)]} then {
unset cond(7) cond(8) elem(btn=); # dispose?
set cond(7) [object create PropertyCondition $prop(name) =]
set cond(8) [object create AndCondition $cond(2) $cond(7)]
set elem(btn=) [$elem(pid) -alias FindFirst Descendants $cond(8)]
}
[$elem(btn1) -alias GetCurrentPattern $patt(invoke)] Invoke
after 1000
[$elem(btn+) -alias GetCurrentPattern $patt(invoke)] Invoke
after 1000
[$elem(btn1) -alias GetCurrentPattern $patt(invoke)] Invoke
after 1000
[$elem(btn=) -alias GetCurrentPattern $patt(invoke)] Invoke
after 1000
# optional, close calc.exe
# kill $pid