Re: filtering alias files by original item
Re: filtering alias files by original item
- Subject: Re: filtering alias files by original item
- From: Kai Edwards <email@hidden>
- Date: Mon, 14 Jan 2002 21:26:40 +0100
>
Subject: Re: filtering alias files by original item
>
Date: Mon, 14 Jan 2002 15:23:20 +0000
>
From: Nigel Garvey <email@hidden>
>
To: "AppleScript Users" <email@hidden>
>
>
Kai Edwards wrote on Sun, 13 Jan 2002 19:11:00 +0100:
>
>
> tell application "Finder"
>
> set startupFolder to startup items folder
>
> set aliasList to startupFolder's alias files
>
> if aliasList {} then
>
> set alias1 to original item of item 1 of aliasList
>
> set filteredList to startupFolder's alias files whose original item = alias1
>
> end if
>
> end tell
>
>
> In theory, I expected the 'set filteredList...' command to return the same
>
> value as <item 1 of aliasList> - but instead it results in an empty list.
>
>
>
> Where am I going wrong?
>
>
This looks like another problem with the Finder's 'whose' filter. It
>
doesn't seem to be able to filter on Finder references either. The
>
following also return empty lists:
>
>
startupFolder's items whose folder is startupFolder
>
>
set csA1 to content space of item 1 of startupFolder
>
startupFolder's items whose content space is csA1
Thanks for the reassurance, Nigel. I was becoming concerned that I'd been
doing something really daffy!
>
'Whose' is said to have been fixed recently so that it now filters
>
correctly on numeric values, but I don't know what the situation is with
>
Finder references. It's probably wisest to restrict the use of 'whose' to
>
strings and booleans for the next few years, until no-one's using pre-9.1
>
systems any more.
Sounds like good advice. At present, I initially write and test on a fairly
old system (OS 8.1, AS 1.1.2) - mainly because some of my clients have a
rather sluggish upgrade policy. :(
Satisfying an older configuration generally minimises any glitches in the
'universal' solutions I provide - although it can also limit the
possibilities of vanilla AS somewhat!
>
For your purposes, a simple loop seems best:
>
>
tell application "Finder"
>
...
>
>
-- ('alias1' changed to 'orig1' to avoid confusion)
Ah yes - meaningful variable names. Clearly my thinking had already become
extremely muddled by this stage!
>
set orig1 to original item of item 1 of aliasList
>
-- Get all the original items *before* looping
>
set origList to original item of startupFolder's alias files
>
>
set filteredList to {}
>
repeat with i from 1 to (count origList)
>
if item i of origList is orig1 then set the end of filteredList to
>
item i of aliasList
>
end repeat
>
filteredList
>
end tell
Yup. That does it for me!
In fact, my original script used a similar loop. However, during the
refining process, I decided - in the interests of efficiency/brevity - to
use filtering instead. (That'll teach me to try and be too clever!)
With the benefit of your insight, I'll be a little more circumspect in my
use of filters from now on.
Thanks again for your comments, which allayed growing fears that my
scripting might have degenerated to a sorry level of wackiness - or even
downright incompetence!
Best wishes.
Kai
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************