I’m trying to simplify a part of a script that I am writing for InDesign
My issue here is that I am trying to count files in a selected folder, and then tell an indesign document to make a new page with a text frame containing the name of the file…
so if my chosen folder contains 4 files named: 1, 2, 3, 4 — then my Indesign document will have: page 1 with a text frame that says “1”, page 2 with a text frame that says “2”… etc
right now my script will make all the pages I need, along with a text frame on each page — the problem is that the text frame on each page all have the same file name in it
I’m sure I’m just overlooking something easy, but my brain hurts!
here’s what I have right now:
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)
set doc_Pages to image_count
tell application “InDesign CS”
activate
set horizontal measurement units of view preferences to points
set vertical measurement units of view preferences to points
set myDocument to make document with properties {page width:612, page height:792}
set facing pages of document preferences of myDocument to false
set pages per document of document preferences of myDocument to doc_Pages
tell document 1
repeat with i from 1 to (count of pages of document)
tell page i
make new text frame with properties {geometric bounds:{669.0, 107.4, 687.6, 504.0}}
set contents of text frame 1 to (my get_name(the_images)) as string
end tell
end repeat
end tell
end tell
–repeat with the_image in the_images
–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