On 2010-10-24, at 9:34 PM, Laurent Sansonetti wrote:
Hi Mark,
Matt already replied but I thought I would give more info.
On Oct 23, 2010, at 10:04 PM, Mark Rada wrote:
Hi,
I've been trying to play with using the Accessibility API to do some automated testing.
From what I have researched, I have to use some C functions that often need a reference passed to the them.
I am at a loss when trying to deal with Pointer objects. I've tried playing with them and googling it, but I just cannot figure out how to turn a pointer into a more useful type or to get what I want out of them.
For example, I can start like this:
framework 'Cocoa'
unless AXAPIEnabled() # only works if I include the parenthesis puts 'Please enable Access for Assistive Devices first' exit 2 end
That's expected, in Ruby methods starting with a capital letter must be called with explicit parentheses, otherwise they are interpreted as constants.
Ah, that makes more sense now.
mail = NSRunningApplication.runningApplicationsWithBundleIdentifier('com.apple.Mail').first mail_object = AXUIElementCreateApplication mail.processIdentifier
names = Pointer.new :object
AXUIElementCopyAttributeNames mail_object, names
But then how do I get the values out of the names pointer? For reference, I found the functions in AXUIElement.h.
It looks like AXUIElementCopyAttributeNames returns a CFArray by reference. So your pointer object is properly created, to retrieve the array after the call you just use
array = names[0]
Then, it should behave like a normal Ruby array.
Ah, that does work, and seems to have worked for a number of other things I am trying to do. The only problem now is when I have something like value = Pointer.new '^v' # pointer to pointer to void AXUIElementCopyAttributeValue mail_object, 'AXHidden', value In this case I am using it right now, it will be returning a boolean, but when I try to dereference it like puts value[0][0] # => 120 it gives me a Fixnum, and then I can keep trying things like puts value[0][1] # => 104 puts value[0][10000] # => 0 And I seem to get nowhere. Is there a way to cast the data back into the type I want it to be? Or am I doing something dumb? Thanks, Mark
Laurent _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel