Wednesday, December 12, 2018

#1 2005-09-01 04:04:27 pm

raymassie
Member
From:: Alameda, CA
Registered: 2005-08-19
Posts: 15
Website

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.


"We're here to inject Art into Commerce." —Tibor Kalman


Filed under: Indesign, microsoft

Offline

 

#2 2005-09-01 10:22:30 pm

Jerome
Member
From:: Ohio
Registered: 2003-06-14
Posts: 709
Website

Re: InDesign list of links to MSWord, or preferably Excel

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.

Applescript:

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


Filed under: Indesign, microsoft

Offline

 

#3 2005-09-02 10:09:37 am

raymassie
Member
From:: Alameda, CA
Registered: 2005-08-19
Posts: 15
Website

Re: InDesign list of links to MSWord, or preferably Excel

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.


"We're here to inject Art into Commerce." —Tibor Kalman

Offline

 

#4 2005-09-02 01:11:20 pm

mleslie
Member
From:: indoors
Registered: 2005-02-09
Posts: 61

Re: InDesign list of links to MSWord, or preferably Excel

So how about this?

Applescript:


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

Last edited by mleslie (2005-09-02 01:29:01 pm)


Filed under: Indesign

Offline

 

#5 2005-09-02 02:36:24 pm

raymassie
Member
From:: Alameda, CA
Registered: 2005-08-19
Posts: 15
Website

Re: 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...


"We're here to inject Art into Commerce." —Tibor Kalman

Offline

 

#6 2006-05-01 10:59:02 pm

krdzine1
Member
Registered: 2004-08-25
Posts: 55

Re: InDesign list of links to MSWord, or preferably Excel

sad
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.

Offline

 

#7 2006-05-02 02:56:51 pm

mleslie
Member
From:: indoors
Registered: 2005-02-09
Posts: 61

Re: InDesign list of links to MSWord, or preferably Excel

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

Applescript:


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


Filed under: Indesign

Offline

 

#8 2006-05-03 10:15:30 am

krdzine1
Member
Registered: 2004-08-25
Posts: 55

Re: InDesign list of links to MSWord, or preferably Excel

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

Offline

 

#9 2007-01-08 04:04:07 pm

r125268
Member
Registered: 2004-05-21
Posts: 43

Re: InDesign list of links to MSWord, or preferably Excel

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


Applescript:


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



Filed under: Indesign, Finder

Offline

 

#10 2010-03-25 08:30:38 am

hripka
Member
Registered: 2004-08-26
Posts: 49

Re: InDesign list of links to MSWord, or preferably Excel

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

Applescript:

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!

Offline

 

#11 2010-03-25 09:11:54 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11526
Website

Re: InDesign list of links to MSWord, or preferably Excel

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

Applescript:


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

Last edited by StefanK (2010-03-25 09:13:23 am)


regards

Stefan

Offline

 

#12 2010-03-25 11:59:34 am

krdzine1
Member
Registered: 2004-08-25
Posts: 55

Re: InDesign list of links to MSWord, or preferably Excel

Tried latest post in CS3... no data sent to .txt file. sad

Offline

 

#13 2010-03-25 12:08:46 pm

hripka
Member
Registered: 2004-08-26
Posts: 49

Re: InDesign list of links to MSWord, or preferably Excel

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


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."

Offline

 

#14 2010-03-25 12:12:10 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11526
Website

Re: InDesign list of links to MSWord, or preferably Excel

krdzine1 wrote:

Tried latest post in CS3... no data sent to .txt file. sad


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

Applescript:



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


regards

Stefan

Offline

 

#15 2010-03-25 01:00:37 pm

hripka
Member
Registered: 2004-08-26
Posts: 49

Re: InDesign list of links to MSWord, or preferably Excel

Thank you so much.

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

Applescript:

repeat until class of parentElement is image

Offline

 

#16 2010-03-25 01:04:52 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11526
Website

Re: InDesign list of links to MSWord, or preferably Excel

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


regards

Stefan

Offline

 

#17 2010-03-25 05:33:40 pm

hripka
Member
Registered: 2004-08-26
Posts: 49

Re: InDesign list of links to MSWord, or preferably Excel

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-o … ment-55391
which worked great!

Offline

 

#18 2015-04-14 05:56:30 pm

nellbern
Member
Registered: 2007-01-16
Posts: 126

Re: InDesign list of links to MSWord, or preferably Excel

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

Applescript:

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)

Offline

 

#19 2015-04-14 08:43:02 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 843

Re: InDesign list of links to MSWord, or preferably Excel

Hi. Opening/closing for access is a trap.

Applescript:

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

Offline

 

#20 2015-04-14 10:58:55 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11526
Website

Re: InDesign list of links to MSWord, or preferably Excel

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

Applescript:


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

Applescript:


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

with

Applescript:


set pageName to name of parent page of parentElement


regards

Stefan

Offline

 

#21 2015-04-15 08:50:27 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 843

Re: InDesign list of links to MSWord, or preferably Excel

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:

tell application "Finder" to set item_list to every item of source_folder


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.

Applescript:

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.

Offline

 

#22 2018-11-28 07:08:11 pm

nellbern
Member
Registered: 2007-01-16
Posts: 126

Re: InDesign list of links to MSWord, or preferably Excel

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.

Applescript:

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

Last edited by nellbern (2018-11-28 07:12:30 pm)

Offline

 

#23 2018-11-29 06:26:40 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 843

Re: InDesign list of links to MSWord, or preferably Excel

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.

Applescript:

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)