Re: When can you use the 'whose' clause (Filter)
Re: When can you use the 'whose' clause (Filter)
- Subject: Re: When can you use the 'whose' clause (Filter)
- From: Jerry Krinock <email@hidden>
- Date: Fri, 11 Apr 2008 15:47:19 -0700
Well, this certainly has been surprising.
Below is my 'whose' tutorial which I believe will guide me in future
projects. I don't yet have a 100% understanding of every reason for
every failure, but I do believe I can write working scripts from now on.
Thanks for all the help.
Jerry
(* Purpose: Since AppleScript references have to translate back and
forth between many objects before getting a result, filtering
lists by searching in a loop can be very slow. We therefore
like to use the filter form 'whose', (or equivalently 'where' or
'that') whenever possible. But it's a little tricky since this
filter can only specify application objects. The following demo
shows four failed and one successful attempt at using 'whose'. *)
tell application "Xcode"
-- projects are an element of the application:
set theProject to project 1
-- targets are elements of projects:
set theTarget to target 1 of theProject
-- build configurations are elements of targets
set buildConfigs to build configurations of theTarget
-- Get desired build configuration (5 attempts follow)
-- This makes a "can't get" error because buildConfigs
-- is a free-standing list and does not know that it contains
-- application objects.
--set aBC to item 1 of buildConfigs whose name is "Release"
-- And this makes a "can't get" error for the same reason. It
-- does not help that I give it a clue that it contains that
-- the list contains 'build configuration' objects
--set aBC to build configuration 1 of buildConfigs whose name is
"Release"
-- And this makes a "can't get" error because the free-standing
-- list buildConfigs does not do 'whose'
--set buildConfigs to build configurations of theTarget
--tell buildConfigs to set aBC to item whose name is "Release"
-- And this makes a "can't get" error because 'whose' must always
-- operate upon a list and return a list
--tell theTarget to set aBC to build configuration whose name is
"Release"
-- But if you add an 's', and then take the 'first' element of
the 'whose'
-- output (there is only 1 anyhow), it works. Thanks, Michelle
Steiner.
tell theTarget to set aBC to first build configuration whose name
is "Release"
log class of aBC & " " & name of aBC & " " & id of aBC as text
end tell
-- Finally, for that perly urge, do it all in one line
tell application "Xcode" to set aBC to first build configuration of
target 1 of project 1 whose name is "Release"
log class of aBC & " " & name of aBC & " " & id of aBC as text
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden