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 11:49:15 -0700
On 2008 Apr, 10, at 19:34, Stockly, Ed wrote:
"Application Objects" refers to objects that belong to applications.
In the
case of the Finder it includes folders and files and windows etc.
Thanks, I get that now, thanks to you and Michelle.
the restriction ... may be in the way your scripts are specifying
objects.
Indeed you are correct. I've put corrected code that works in a
footnote [1].
'Whose' clauses are implemented by application developers. Some
developers may choose to implement them in a more limited way than
others, but some allow a wide range of elements to be addressed by
'whose' clauses.
But I've never seen an application's Dictionary explain whether or not
'whose' has been implemented. So I use try it, like this:
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
-- All of the above works OK. Now, the trouble begins when I try
-- and pick out a 'build configuration' whose name is "Release"...
-- Failed Attempt 1, causes "Cannot get..." error:
--set aBC to item 1 of buildConfigs whose name is "Release"
-- Failed Attempt 2, also causes "Cannot get..." error:
--set aBC to build configuration 1 of buildConfigs whose name is
"Release"
-- Failed Attempt 3, also causes "Cannot get..." error:
--tell theTarget to set aBC to build configuration whose name is
"Release"
-- But it succeeds if I use a loop
repeat with buildConfig in (build configurations of theTarget)
if name of buildConfig is "Release" then
set aBC to buildConfig
exit repeat
end if
end repeat
end tell
Since all three of my attempts failed, I conclude that application
"Xcode" does not implement 'whose' clauses for 'build configuration'
objects. Is there any way I could have predicted this?
I would like to use 'whose' as much as possible since, when they work,
they are way way faster than loops.
You may try looking at the free list and record OSAX from Late Night
Software.
I just installed and tried it. It does have some cool stuff, but not
the ability to support 'whose' in lists of arbitrary objects. The
closest thing I can find is command 'filter list', which extracts
specified types of objects from a list.
FYI, you don't need to declare local variables. The only
AppleScript context where I believe that's useful is when you're
debugging with ScriptDebugger and you're in a handler.
Got it. Like many people, I "learnt" AppleScript before I found the
documentation :(
Jerry
[1]
As long as that is a valid Finder object it should work...
Ah, that is correct. In my first line, ("set myHome to..."), if I
change "item 1" to "folder 1" (as you did in your script), then it
magically "becomes" a Finder "application object", and then everything
else works.
I can even drill down one level deeper and suck out the names now...
tell application "Finder"
set myHome to folder 1 of (folders whose name is "jk") in folder
"JMiniHD:Users:"
log myHome
-- Syntax from Apple documentation
set myLib1 to folder 1 of (folders whose name is "Library") in
myHome
log (class of myLib1 as string) & " myLib1: " & (POSIX path of
(myLib1 as alias))
-- Cool shorthand, thanks to Ed Stockly
set myLib2 to item 1 of myHome whose name is "Library"
log (class of myLib2 as string) & " myLib2: " & (POSIX path of
(myLib2 as alias))
set myFolders to name of every folder in ((folders whose name
contains "k") in myLib2)
set msg to (((count of myFolders) as string) & " folders:" &
return & myFolders as string)
log (msg & return) as string
end tell
tell application "Finder" to set myFolders to every folder of entire
contents of myHome whose name contains "E"
Hmmm...that might require a long timeout there, Ed. :))
_______________________________________________
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