The documentation in the appscript objc-trunk randomly uses ruby in the section called "Performance Issues".
require "appscript"
include Appscript
desiredEmail = 'sam.brown@foo.com'
p app('Address Book').people[
its.emails.value.contains(desiredEmail)
].name.get
How would this be written in Objective-C? I apologize if this seems like an overly basic question, I have 0 experience with Ruby.
Thanks.
If you run the ruby script and use ASTranslate
it should translate the raw appscript commands to Objc-appscript.
I think it will look something like this. I haven't run the tool to make the glue code so I'm guessing about the way the app name shows up.
#import "AddressBookGlue.h" //Dont know the precise name
AddressBookApplication *abApp=[[AddressBookApplication alloc] initWithName: @"Address Book.app"];
NSString *desiredEmail=@"sam.brown@foo.com"
NSString *returnedName= [[[[[[abApp people] emails] value] contains:desiredEmail] name] get];
Basically, it follows the same rules that Objectic-c uses when converting from a dot syntax: anywhere there is a dot in the original syntax, expect a bracket in Objective-C.
I might add that if you're going to be doing a lot of this type scripting, it would be best to spend a day or two learning the basics of ruby or python. It's a lot easier to work with OSA in a dot syntax than a nested syntax. Just looking at all those brackets in the documentation for Objc-appscript makes my eyes water.