• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Script to Get Finder Selection?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script to Get Finder Selection?


  • Subject: Re: Script to Get Finder Selection?
  • From: John Delacour <email@hidden>
  • Date: Fri, 1 Aug 2003 16:21:41 +0100
  • Mac-eudora-version: 6.0a29

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 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




.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Script to Get Finder Selection?
      • From: Paul Skinner <email@hidden>
References: 
 >Re: Script to Get Finder Selection? (From: Matthew Smith <email@hidden>)

  • Prev by Date: Re: Remote Apple Events
  • Next by Date: Re: keystroke reference?
  • Previous by thread: Re: Script to Get Finder Selection?
  • Next by thread: Re: Script to Get Finder Selection?
  • Index(es):
    • Date
    • Thread