Repeat Routine Question

I need to create a repeat routine that places items on a page. The total number that can be placed on a page is 7. And I want 7 placed on every page, even if there are only 3 items to place. Ideally, if there were three, it would place item 1 three times, item 2 two times and item 3 two times.

On the page it would look like this:

1
2
3
1
2
3
1

The pattern would be the same for any other number. It would simply loop them, starting again at 1 until there are 7 on a page.

So I am starting my script with a list of items to process. How many items in this list will be different from time to time. I need the repeat routine to do it 7 times, regardless of how many items there are.

Any suggestions of how to do this?

I could create a loop that repeats 7 times and nest a second loop in that one that takes items out of the list and then have the repeat routine run “while” the count of the list is more than one. This would result in the last item being placed the number of times needed to make 7. Not an ideal solution, but better than nothing. Any other ideas would be appreciated.

Hi viidesign,

Something like this after you’ve gotten your input list to less than seven items.

set temp_list to {}
set input_list to {1, 2, 3}
repeat while (count temp_list) < 7
	set temp_list to temp_list & input_list
end repeat
set output_list to items 1 thru 7 of temp_list

gl,
kel

Hi,

Here’s a better example:

-- make a list
set num_list to {}
repeat with i from 1 to 25
	set end of num_list to i
end repeat

-- make the pages
set c to count num_list

-- make the whole pages if any
set whole_pages to c div 7
if whole_pages > 0 then
	set num_whole_pages to whole_pages * 7
	set page_list to {}
	repeat with i from 1 to num_whole_pages by 7
		set this_page to items i thru (i + 6) of num_list
		set end of page_list to this_page
	end repeat
end if

-- make the last page if any
set item_pointer to c mod 7
if item_pointer > 0 then
	set last_page to items -item_pointer thru -1 of num_list
	copy last_page to temp_list
	repeat while (count temp_list) < 7
		set temp_list to temp_list & last_page
	end repeat
	set whole_last_page to items 1 thru 7 of temp_list
	set end of page_list to whole_last_page
end if

page_list

gl,
kel

Thanks and that does work. I also worked out another way to do it. Here’s an example with a dialog that displays the day of the week. If you increase the repeat number it simply starts back to the first day of the week and keeps cycling through them.

set tempdaysofweek to {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}

set myiterate to 1

repeat 12 times
	set this_item to item myiterate of tempdaysofweek
	display dialog "It is " & this_item & " today!" buttons {"Ok"}
	if myiterate is equal to (count of tempdaysofweek) then
		set myiterate to 1
	else
		set myiterate to myiterate + 1
	end if
end repeat

Hi viidesign,

Ok. I was thinking that you might have a variable list.

gl,
kel

Yes, I will have a variable list and what you’ve provided will work well for what I need (once I figure it all out). Much better, actually, then the one I put together.

In actuality, I will have a list of aliases. If there are more than 7, I will need to split them up into pages (as you’ve done).

Using your script, I could use the “page_list” to direct the item number of my original alias list in placing the files onto the pages.

With a little more testing, the one issue that your script runs into is the fact that if the figure is under 3, it doesn’t create the page_list. I suppose I could use an else statement and use my script for anything with less than 7 and yours for anything with more than 7…

or


property tempdaysofweek : {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}
property numberOfIterations : 12

set numberOfTempdaysofweek to count tempdaysofweek

repeat with myiterate from 0 to (numberOfIterations - 1)
	set this_item to item ((myiterate mod numberOfTempdaysofweek) + 1) of tempdaysofweek
	display dialog "It is " & this_item & " today!" buttons {"Ok"}
end repeat

Hi viidesign,

Oops. put the line for the list in the wrong place:

-- make a list
set num_list to {}
repeat with i from 1 to 24
	set end of num_list to i
end repeat

-- make the pages
set c to count num_list
set page_list to {}

-- make the whole pages if any
set whole_pages to c div 7
if whole_pages > 0 then
	set num_whole_pages to whole_pages * 7
	repeat with i from 1 to num_whole_pages by 7
		set this_page to items i thru (i + 7 - 1) of num_list
		set end of page_list to this_page
	end repeat
end if

-- make the last page if any
set item_pointer to c mod 7
if item_pointer > 0 then
	set last_page to items -item_pointer thru -1 of num_list
	copy last_page to temp_list
	repeat while (count temp_list) < 7
		set temp_list to temp_list & last_page
	end repeat
	set whole_last_page to items 1 thru 7 of temp_list
	set end of page_list to whole_last_page
end if

page_list

Edited: made minor adjustments in the script.

Edited: made last adjustments:

-- make a list
set num_list to {}
repeat with i from 1 to 50
	set end of num_list to i
end repeat

-- make the pages
set c to count num_list
set page_list to {}

-- get the whole pages if any
set whole_pages to c div 7
if whole_pages > 0 then
	set num_whole_pages to whole_pages * 7
	repeat with i from 1 to num_whole_pages by 7
		set this_page to items i thru (i + 7 - 1) of num_list
		set end of page_list to this_page
	end repeat
end if

-- make the last page if any
set item_pointer to c mod 7
if item_pointer > 0 then
	set last_page to items -item_pointer thru -1 of num_list
	copy last_page to temp_list
	repeat while (count temp_list) < 7
		set temp_list to temp_list & last_page
	end repeat
	set whole_last_page to items 1 thru 7 of temp_list
	set end of page_list to whole_last_page
end if

{"Number of pages: " & (count page_list), page_list}

gl,
kel