need help with indesign

trying to build a script that will copy and paste chosen files from a folder from illustrator into indesign document

I have it working now so that it will open each illustrator file, copy it’s contents, and then paste them into an InDesign file
I’m trying to work out the issue of putting the file name of the ill file onto the page, so that I know what the name of the actual file is
this script keeps putting all the names on page 1

Also, this is my first script with InDesign, so I am having so much trouble on figuring how to tell it exactly what I want to do…here’s the rundown:

  1. open files from chosen folder 1 at a time in illustrator
  2. copy all contents
  3. place copied contents into Indesign document on subsequent pages
  4. make a text box on page that file was placed and make the text “the file name”

I am basically hacking this script together to this point, so any improvment would be greatly appreciated

NOTE: Illustrator preferences for my script to actually copy into Indesign as editable shapes have to be changed to:
“File Handling and Clipboard” - “Clipboard on Quit” = AICB-Preserve Paths

my script is as follows:

property file_types : {“EPSf”, “EPSP”}
property file_extensions : {“eps”}

set the_folder to (choose folder with prompt “Choose folder containing images to catalog:”)
set the_images to get_folder_list(the_folder, file_types, file_extensions, true, false)
if the_images = {} then
beep
display dialog “No valid images found in chosen folder.” buttons {“OK”} default button 1 with icon 0 giving up after 10
return
end if

set image_count to (count the_images)

tell application “InDesign CS”
set my_document to make document with properties {page width:612, page height:792}
set facing pages of document preferences of my_document to false
end tell

repeat with the_image in the_images

tell application "Illustrator CS"
	activate
	open the_image as alias with options {update legacy text:true} without dialogs
	tell document 1
		set visible of every layer to true
		set locked of every layer to false
		set locked of every page item to false
		set selected of (every page item) to true
		tell application "Illustrator CS" to copy
		tell application "Illustrator CS" to close current document saving no
		tell application "InDesign CS"
			activate
			paste
			tell my_document
				set myTextFrame to make new text frame with properties {geometric bounds:{670.49925, 36.0, 696.74925, 576.0}}
				set contents of myTextFrame to (my get_name(the_image))
				tell application "System Events"
					keystroke "G" using shift & command down
				end tell
				tell application "InDesign CS"
					set new_page to make new page at end of my_document
					tell application "Illustrator CS" to activate
				end tell
			end tell
			tell application "Illustrator CS" to activate
		end tell
	end tell
end tell

end repeat

on get_folder_list(the_folder, file_types, file_extensions, with_subfolders, inc_folders)
set the_files to {}
tell application “Finder” to set folder_list to every item of folder the_folder
repeat with new_file in folder_list
try
set temp_file_type to file type of new_file
set temp_file_extension to name extension of new_file
on error
set temp_file_type to “folder”
set temp_file_extension to “”
end try
if file_types contains temp_file_type or file_extensions contains temp_file_extension then set end of the_files to (new_file as string)
if temp_file_type = “folder” then
if inc_folders = true then set end of the_files to (new_file as string)
if with_subfolders = true then set the_files to the_files & my get_folder_list((new_file as string), file_types, file_extensions, with_subfolders, inc_folders)
end if
end repeat
return the_files
end get_folder_list

on get_name(the_path)
set old_delim to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {“:”}
set the_name to (text item -1 of (the_path as string))
set AppleScript’s text item delimiters to old_delim
return the_name
end get_name