Re: Apple Script for File Selection
Re: Apple Script for File Selection
- Subject: Re: Apple Script for File Selection
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 15 Jun 2010 13:30:55 -0400
Jesse> is it possible to write a script which chooses every third
file in a folder, and then a separate one which chooses every other
file?
Almost certainly, but it depends on what you mean by "chooses". Ed's
script will create a list of those files which you can then manipulate
with more AppleScript. If you want to actually highlight those files
in a Finder window, that's a different sort of "choose", although with
a combination of "open" on the folder and maybe "set selection" you
could use Ed's script to do that, too.
Ed> Here's a snippet that could get you started.
Your code will miss some files. For instance, suppose there are 9
files. On the iteration where it adds the 7th item to the by2List, it
will attempt to add the 10th item to the by3List and exit the loop
because 10>9, never getting to the next iteration where the 9th item
would be added to the by2List.
A more straightforward solution is to loop through the whole list and
add each item to the appropriate list according to the remainder when
the index is divided by 2 or 3:
set by3Files to {}
set by2Files to {}
set fileCount to the count of fileList
repeat with x from 1 to fileCount
set theFile to item x of fileList
if x mod 2 is 1 then set end of by2Files to theFile
if x mod 3 is 1 then set end of by3Files to theFile
end repeat
As with Ed's code, that will return the 1st, 3rd, 5th, etc. items in
the by2List and the 1st,4th,7th, etc. items in the by3List. If you
want the 2nd,4th,6th and 3rd,6th,9th, respectively, replace the "is
1"s with "is 0"s.
--
Mark J. Reed <email@hidden>
_______________________________________________
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