Re: Scripting Bridge && filteredArrayUsingPredicate
Re: Scripting Bridge && filteredArrayUsingPredicate
- Subject: Re: Scripting Bridge && filteredArrayUsingPredicate
- From: has <email@hidden>
- Date: Thu, 27 Dec 2007 12:16:43 +0000
led248 wrote:
Anybody using Scripting Bridge with filteredArrayUsingPredicate ???
I've tried Apple's example code -- it's the last code snippet in
"Scripting Bridge Release Notes for Mac OS X v10.5" http://developer.apple.com/releasenotes/ScriptingAutomation/RN-ScriptingBridge/index.html
But it does not work.
[...]
NSPredicate *startsWithM = [NSPredicate
predicateWithFormat:@"name BEGINSWITH 'M'"];
SBElementArray *desiredDisks = [[finder disks]
filteredArrayUsingPredicate:startsWithM];
NSArray *nameArray = [desiredDisks
arrayByApplyingSelector:@selector(name)];
[...]
ErrorNumber = -1728;
Error -1728 = object(s) not found. It's up to individual applications
to decide how to behave in response to a given command, and for
whatever reason, the Finder elects to raise an error rather than
return an empty list if the 'name of (every disk whose name starts
with "M")' query fails to match anything. By comparison, a similar
query in TextEdit, e.g. 'name of (every document whose name starts
with "d")', would return an empty list on no matches. Blame Apple for
failing to provide scriptable application developers with adequate
design guidelines, particularly in the pre-SIG days. As a result, it's
up to users to figure out exactly how individual applications'
scripting interfaces behave in order to control them effectively.
In this case, you can either trap the error raised and recover
accordingly, or use the 'exists' command to check if the query will
match anything before trying to obtain the actual data. e.g. Using
objc-appscript:
// To create a Finder glue: osaglue FN Finder
FNApplication *finder;
FNReference *ref;
NSArray *diskNames;
finder = [[FNApplication alloc] initWithBundleID:
@"com.apple.finder"];
ref = [[[finder disks] byTest: [[FNIts name] beginsWith: @"M"]]
name];
if ([[[ref exists] send] boolValue])
diskNames = [[ref get] send];
else
diskNames = [NSArray array];
NSLog(@"%@", diskNames);
[finder release];
HTH
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden