Re: Script to Get Finder Selection?
Re: Script to Get Finder Selection?
- Subject: Re: Script to Get Finder Selection?
- From: Paul Skinner <email@hidden>
- Date: Mon, 4 Aug 2003 07:50:48 -0400
On Friday, August 1, 2003, at 11:21 AM, John Delacour wrote:
At 2:12 pm +1000 1/8/03, Matthew Smith wrote:
tell application "Finder"
set selList to selection
repeat with oneItem in selList
-- now do something with the each item, ie oneItem.
end repeat
end tell
One thing to note, is to set a variable to what is the selection,
otherwise
it is possible for the user to change the selection while your script
is
processing. This way, the items will be what the selection was at the
beginning of the script.
That cannot happen
It is possible to alter a selection and break a script.
tell application "Finder"
repeat with i from 1 to (length of (get selection))
set ls to item i of (get selection)
delay 1
say (i as text)
end repeat
end tell
deselect after running-->Can't get item 2 of {}.
and a variable is not necessary in this case. In the script below
'get selection' is evaluated only once at the beginning of the loop
and no change to the selection while the script is running will make
any difference.
tell application "Finder"
set ls to {}
repeat with i in (get selection)
set end of ls to name of i as Unicode text
delay 2
end repeat
end tell
ls
The script below demonstrates that even though ls is changed in the
loop, it retains its initial value throughout the loop and even though
the loop extends the length of ls by 1 at every iteration, there are
only as many iterations as there are items in the original list.
set ls to {1, 2, 3, 4, 5}
repeat with i in ls
set contents of i to i * 2
set end of ls to 3
end repeat
ls
--> {2, 4, 6, 8, 10, 3, 3, 3, 3, 3}
--JD
I think this simpler example shows the point you were making more
clearly. YMMV.
When you put an expression in a repeat command you only evaluate it
once.
When the repeat begins it establishes the value and uses it throughout
the repeat.
In this case it prevents an infinite loop.
set x to 10
repeat x times
set x to x + 1
end repeat
PS
Hey, What's up with alias list when used with finder selection?
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.