InDesign list of links to MSWord, or preferably Excel

howdy all,

i’m a complete novice at this, so apologies first…

i’m trying to write a script that will retrieve from InDesign a list of the links and some of their properties and place that info into an Excel document. I’ve managed to get as far as retrieving a list of the links to an MSWord file, but i can’t figure out how to add a delimiter so the list returns as one big clump. i haven’t even tried to get to the Excel part…

my full end-result need is to have the file name, the file type, and the file path, each in it’s own column of the Excel file. it would also be nice if it would indicate which files were missing, but i know i’m already pushing it…

here’s what i have now:

tell application “InDesign CS”
activate
tell active document
set LinkName to (name of every link as list)
end tell
end tell

tell application “Microsoft Word”
activate
insert text (LinkName as string) at end of text object of active document
end tell

any help is greatly appreciated
thanks in advance
ray.

I don’t know excell, or how to refer to the text fields to fill them, but this should work for word. You might also want to consider just writing a tab delimited file which could be imported by Excell or a database into the fields that you need to populate.

tell application "InDesign CS"
	activate
	tell document 1
		set LinkFiles to name of every link
	end tell
end tell
tell application "Microsoft Word"
	activate
	tell document 1
		repeat with i from 1 to count of LinkFiles
			set contents of selection to item i of LinkFiles & return
		end repeat
	end tell
end tell

Hi Jerome,

thanks for the help! unfortunately, i received this error: Microsoft Word got an error: Can’t set contents of selection of document 1 to “logo_black.ai”.

your suggestion of a tab-delimited file is fine as well. how could i make that happen?

thanks again
ray.

So how about this?


set LinkFiles to {}
set fileTypes to {}
set filePaths to {}

set nameInput to (display dialog "Enter name for the image link listing file:" default answer short date string of (current date) & " - links list")
set newFileName to text returned of nameInput
set outputFile to (path to current user folder as text) & "Desktop:" & newFileName

tell application "InDesign CS"
	tell document 1
		set LinkFiles to name of every link
		set fileTypes to link type of every link
		set filePaths to file path of every link
	end tell
end tell

--creates (or opens if exists) a named file on the users desktop.
set WiP to open for access file outputFile with write permission
--then empties the file, just in case.
set eof WiP to 0

--and loops thru all list items and writes each in turn to the file.
repeat with w from 1 to count of LinkFiles
	write item w of LinkFiles & tab & item w of fileTypes & tab & item w of filePaths & return to WiP starting at eof
end repeat
close access WiP

Basically this will pull the image link names, link types (image file types) and complete file paths for all links in the current InDesign document. Then it runs a loop writing matching sets of items, separated by tabs, to a simple text file on your desktop. Then open the text file in whatever program you want. If you want to use the list in Excel, either import it or drag and drop on Excel’s icon.

Kind of quick and dirty, but it seems to do what you are asking for.

Mark

DUDE! that works so well i think i’m going to cry… as a matter of fact, if you send me your address i’ll send you a bottle of wine or some chocolate or something…

:frowning:
got the error “InDesign CS got an error: File some object wasn’t found.”
Does it not work if you’re missing a link? It’s what I was trying to use it for… a report of missing files.

Yep, looks like it stumbles over missing links (or more accurately, their file paths). Try this version:


set LinkFiles to {}
set fileTypes to {}
set filePaths to {}

set nameInput to (display dialog "Enter name for the image link report:" default answer short date string of (current date) & " - links list.txt")
set newFileName to text returned of nameInput
set outputFile to (path to current user folder as text) & "Desktop:" & newFileName

tell application "InDesign CS"
	tell document 1
		set allLinks to id of every link
		repeat with theLink from 1 to count allLinks
			copy name of link theLink to end of LinkFiles
			copy link type of link theLink to end of fileTypes
			--get link paths, or set message if missing...
			set linkStat to status of link theLink
			if linkStat = normal then
				copy file path of link theLink to end of filePaths
			else if linkStat = link missing then
				copy "** LINK MISSING **" to end of filePaths
			end if
		end repeat
	end tell
end tell

set WiP to open for access file outputFile with write permission
set eof WiP to 0

repeat with w from 1 to count of LinkFiles
	write item w of LinkFiles & tab & item w of fileTypes & tab & item w of filePaths & return to WiP starting at eof
end repeat
close access WiP

BEEEEE----UUUUUU-----TIMUS!!!
Thanks. that worked perfectly

Hi, Thanks a LOT for this script!!! I am trying to set up additional script that will process all Indesign files in the folder. But I do not know how to set up just one output file for this. What I am trying to do is to have a list of lets say 100 indesign files with all images in one document (no file path) just image #.

Can you help resolve ? Thanks Dawid


set LinkFiles to {}


set nameInput to (display dialog "Enter name for the image link listing file:" default answer short date string of (current date) & " - links list")
set newFileName to text returned of nameInput
set outputFile to (path to current user folder as text) & "Desktop:" & newFileName

on open sourceFolders
	repeat with sourceFolder in sourceFolders
		tell application "Finder"
			try
				-- If you would like to include subfolders, you say - every file of entire contents of folder. 
				set idFiles to (every file of folder sourceFolder whose file type is "IDd3") as alias list
			on error -- work around bug if there is only one file 
				set idFiles to (every file of folder sourceFolder whose file type is "IDd3") as alias as list
			end try
		end tell
		
		if idFiles is not {} then
			tell application "InDesign CS"
				set user interaction level to never interact
				repeat with i from 1 to count of idFiles
					open item i of idFiles
					tell document 1
						
						set LinkFiles to name of every link
					end tell
					
					
					--creates (or opens if exists) a named file on the users desktop.
					set WiP to open for access file outputFile with write permission
					
					
					--and loops thru all list items and writes each in turn to the file.
					repeat with w from 1 to count of LinkFiles
						write item w of LinkFiles & return to WiP starting at eof
					end repeat
					close access WiP
				end repeat
				set user interaction level to interact with all
			end tell
		end if
		return 10 -- try again in 10 seconds 
	end repeat
end open



For this script, which finds the name, link type and file path of all the links:

set LinkFiles to {}
set fileTypes to {}
set filePaths to {}

set nameInput to (display dialog "Enter name for the image link listing file:" default answer short date string of (current date) & " - links list")
set newFileName to text returned of nameInput
set outputFile to (path to current user folder as text) & "Desktop:" & newFileName

tell application "InDesign CS"
   tell document 1
       set LinkFiles to name of every link
       set fileTypes to link type of every link
       set filePaths to file path of every link
   end tell
end tell

--creates (or opens if exists) a named file on the users desktop.
set WiP to open for access file outputFile with write permission
--then empties the file, just in case.
set eof WiP to 0

--and loops thru all list items and writes each in turn to the file.
repeat with w from 1 to count of LinkFiles
   write item w of LinkFiles & tab & item w of fileTypes & tab & item w of filePaths & return to WiP starting at eof
end repeat
close access WiP

How would I get the page number that the link is on, and the scale it is used at?

Thanks in Advance!

Maybe there is a shorter way, but this should work.


set nameInput to (display dialog "Enter name for the image link listing file:" default answer short date string of (current date) & " - links list")
set newFileName to text returned of nameInput
set outputFile to (path to current user folder as text) & "Desktop:" & newFileName & ".txt"

--creates (or opens if exists) a named file on the users desktop.
try
	set WIP to open for access file outputFile with write permission
	tell application "Adobe InDesign CS3"
		tell document 1
			repeat with oneLink in (get links)
				set {name:linkFile, link type:fileType, file path:filePath, parent:parentElement} to oneLink
				repeat until class of parentElement is image
					set parentElement to parent of parentElement
				end repeat
				tell parentElement to set imageScale to "h: " & horizontal scale & " v: " & vertical scale of parentElement
				repeat until class of parentElement is page
					set parentElement to parent of parentElement
				end repeat
				set pageName to name of parentElement
				set writeString to linkFile & tab & fileType & tab & filePath & tab & imageScale & tab & pageName & return
				tell me to write writeString to WIP starting at eof
			end repeat
		end tell
	end tell
	close access WIP
on error
	try
		close access file outputFile
	end try
end try

Tried latest post in CS3… no data sent to .txt file. :frowning:

Yes, me too.

Then, when I remove the writing to a file parts
Now, while trying to debug, I am getting the error message “The variable parentElement is not defined.”

actually I test all my scripts before posting them. It works fine on Leopard.
In Snow Leopard maybe the write command within the Indesign block causes the error.
Here is a version with a extern writeToFile handler



set nameInput to (display dialog "Enter name for the image link listing file:" default answer short date string of (current date) & " - links list")
set newFileName to text returned of nameInput
set outputFile to (path to desktop as text) & newFileName & ".txt"

--creates (or opens if exists) a named file on the users desktop.
try
	set WIP to open for access file outputFile with write permission
	tell application "Adobe InDesign CS3"
		tell document 1
			repeat with oneLink in (get links)
				set {name:linkFile, link type:fileType, file path:filePath, parent:parentElement} to oneLink
				repeat until class of parentElement is image
					set parentElement to parent of parentElement
				end repeat
				tell parentElement to set imageScale to "h: " & horizontal scale & " v: " & vertical scale of parentElement
				repeat until class of parentElement is page
					set parentElement to parent of parentElement
				end repeat
				set pageName to name of parentElement
				set writeString to linkFile & tab & fileType & tab & filePath & tab & imageScale & tab & pageName & return
				writeToFile of me from writeString into WIP
				
			end repeat
		end tell
	end tell
	close access WIP
on error
	try
		close access file outputFile
	end try
end try


on writeToFile from theText into theID
	write theText to theID starting at eof
end writeToFile

Thank you so much.

Once in a while I am still getting the error message, “The variable parentElement is not defined.”

repeat until class of parentElement is image

the variable is defined in the line above. Every link should have a parent element

Thank you very much for your help. That helped me figure it out.

Someone off list sent me a hint about
LinkExport-Pro_1a.jsx
from
http://indesignsecrets.com/get-a-list-of-images-in-your-document.php#comment-55391
which worked great!

Thanks Stefan this is exactly what I need but I need to change it to batch a group of ID selected files from a folder. I’m getting an error:

File file Macintosh HD:Users:user:Desktop:List of Linked files.txt is already open
Why? this file is not even open

set source_folder to choose file with prompt "Select folder containing Indesign Docs to get a list of files linked" with multiple selections allowed without invisibles
tell application "Finder" to set item_list to every item of source_folder
set thisFile to (path to desktop as text) & "List of Linked files.txt"

repeat with this_item in item_list
	
	try
		set WIP to open for access file thisFile with write permission
		tell application "Adobe InDesign CS4"
			--ignore dialogs
			set user interaction level of script preferences to never interact
			open this_item
			

-->>from Macsripter -StefanK
			repeat with oneLink in (get links)
				set {name:linkFile, link type:fileType, file path:filePath, parent:parentElement} to oneLink
				repeat until class of parentElement is image
					set parentElement to parent of parentElement
				end repeat
				tell parentElement to set imageScale to "h: " & horizontal scale & " v: " & vertical scale of parentElement
				repeat until class of parentElement is page
					set parentElement to parent of parentElement
				end repeat
				set pageName to name of parentElement
				set writeString to linkFile & tab & fileType & tab & filePath & tab & imageScale & tab & pageName & return
				writeToFile of me from writeString into WIP
			end repeat
			
			--=========	
		end tell
		close access WIP
	on error
		try
			close access file thisFile
		end try
		
	end try
end repeat

on writeToFile from theText into theID
	write theText to theID starting at eof
end writeToFile

Browser: Safari 537.36
Operating System: Mac OS X (10.8)

Hi. Opening/closing for access is a trap.

set stuff to "ABC123"
tell application "Finder" to write stuff to ((make file) as alias)

There are two major issues in your script
¢ Indesign does not recognize Finder object specifier
¢ The document reference is missing

Regarding the write routine I recommend to put the output into a list and write the list to disk at the end of the script


set source_folder to choose file with prompt "Select folder containing Indesign Docs to get a list of files linked" with multiple selections allowed without invisibles
tell application "Finder" to set item_list to every item of source_folder
set thisFile to (path to desktop as text) & "List of Linked files.txt"

set outputList to {}
repeat with this_item in item_list
	set currentDocument to this_item as text
	tell application "Adobe InDesign CS4"
		--ignore dialogs
		set user interaction level of script preferences to never interact
		open currentDocument
		tell document 1
			set end of outputList to {name of it, ""}
			repeat with oneLink in (get links)
				set {name:linkFile, link type:fileType, file path:filePath, parent:parentElement} to oneLink
				repeat until class of parentElement is image
					set parentElement to parent of parentElement
				end repeat
				tell parentElement to set imageScale to "h: " & horizontal scale & " v: " & vertical scale of parentElement
				repeat until class of parentElement is page
					set parentElement to parent of parentElement
				end repeat
				set pageName to name of parentElement
				
				set writeString to linkFile & tab & fileType & tab & filePath & tab & imageScale & tab & pageName
				set end of outputList to writeString
			end repeat
			set end of outputList to ""
		end tell
		close document 1
		--=========    
	end tell
	
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set outputList to outputList as text
set text item delimiters to TID


try
	set WIP to open for access file thisFile with write permission
	write outputList to WIP starting at eof
	close access WIP
on error
	try
		close access file thisFile
	end try
end try


If you get an error “The variable parentElement is not defined” replace


repeat until class of parentElement is page
	set parentElement to parent of parentElement
end repeat
set pageName to name of parentElement

with


set pageName to name of parent page of parentElement