InDesign list of links to MSWord, or preferably Excel

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

Hello, again. It appears that a good portion of this code is descended from previous posts”some by newbies”from a decade ago. No offense to anyone past or present, but the central InDesign parts aren’t very concise or efficient. There’s also some redundant bits.

This:

is equivalent to the line immediately before it”“set source_folder…””as it produces the same alias(es); the previous line’s logic is also confusing, as the variable and prompt reference a folder, when it actually concerns files.

My approach is a ground-up rewrite.

set aliasTarget to choose file with prompt "Select InDesign files to scavenge their links." with multiple selections allowed without invisibles
set stuff to {}

repeat with aFile in aliasTarget
	set text item delimiters to tab
	tell application "Adobe InDesign CS3"
		set docTarget to open aFile
		tell docTarget to repeat with target in all graphics
			tell target to set stuff's end to {parent's parent's name, "h: " & horizontal scale & "  v: " & vertical scale} & item link's {name, file path, link type, status} & return as text
		end repeat
		close docTarget
	end tell
end repeat

set my text item delimiters to ""
tell application "Finder" to write (stuff as text) to ((make file with properties {name:"List of Linked files.txt"} at desktop) as alias)

© 2015, Marc Anthony. All rights reserved.

I’m using the script below & getting this error:
error “Adobe InDesign CC 2017 got an error: Invalid object for this request.” number 30614.
Can’t figure it out why in some documents it works & the others don’t. Also is it possible keep writing on the same text file? If I running it again I have to delete previous text file.

set aliasTarget to choose file with prompt "Select InDesign files to get a list of the link names in a text file." with multiple selections allowed without invisibles

set stuff to {}

repeat with aFile in aliasTarget
	set text item delimiters to tab
	tell application "Adobe InDesign CC 2017"
		set user interaction level of script preferences to never interact
		
		set docTarget to open aFile
		set DocName to (name of active document as string) & return
		
		tell docTarget to repeat with target in all graphics
			tell target to set stuff's end to item link's {name} & DocName as string
			
		end repeat
		close docTarget saving no
		set user interaction level of script preferences to interact with all
		
	end tell
end repeat

set my text item delimiters to ""
tell application "Finder" to write (stuff as text) to ((make file with properties {name:"XXXX files.txt"} at desktop) as alias)

Model: iMac
AppleScript: Version 2.10 (194)
Browser: Safari 537.36
Operating System: macOS 10.14

There are some desirable modifications, however, none account for the intermittent behavior, other than the potential for the code to allow non-ID file types to be chosen. You’ve also made functional changes which no longer necessitate some features from the original example. Remove all lines referencing TIDs, all coercions, and the brackets around item link’s name, as that single item is already a text. If you want to keep appending to a file, then you have to open/close access and write to EOF; use StefanK’s example from post #20.

set aliasTarget to choose file of type "IDd5" with prompt "Select InDesign files to get a list of the link names in a text file." with multiple selections allowed without invisibles --enforces ID file types

set stuff to ""

repeat with aFile in aliasTarget
	tell application "Adobe InDesign CS3"
		set user interaction level of script preferences to never interact
		set docTarget to open aFile
		tell docTarget to repeat with targ in all graphics
			tell targ to set stuff to stuff & item link's name & " " & docTarget's name & return
		end repeat
		close docTarget saving no
		set user interaction level of script preferences to interact with all
	end tell
end repeat

Thanks Marc for the suggestion. I discovered why the script was stopping
→ error “Invalid object for this request.” number 30614.

There are images that are not linked. They were dragged & dropped from Photoshop or Illustrator hence they will not show in the links palette. I’m adding the try error statement but I want to continue if the error happens?

set aliasTarget to choose file of type "IDd8" with prompt "Select InDesign files to get a list of the link names in a text file." with multiple selections allowed without invisibles --enforces ID file types
set stuff to ""
repeat with aFile in aliasTarget
	tell application "Adobe InDesign CC 2017"
		set user interaction level of script preferences to never interact
		set docTarget to open aFile
		tell docTarget to repeat with targ in all graphics
			try
				tell targ to set stuff to stuff & item link's name & " " & docTarget's name & return
				
			on error number 30614
				--display dialog "Ignore error & continue"
			end try
		end repeat
		close docTarget saving no
		set user interaction level of script preferences to interact with all
	end tell
end repeat