Copy link to clipboard
Copied
I'm looking for assistance with creating a simple Applescript that will parse through all linked files in an InDesign document and find/replace a portion of the link's path.
Background
The volume name at our office is changing slightly and that will break ALL our links within InDesign. The change is so minimal but it's at the root level, IT is removing a space in our server volume name.
Example
Current Link: /Volumes/Our Server/Client/Division/ProjectFolder/Links/image.psd
Future Link: /Volumes/OurServer/Client/Division/ProjectFolder/Links/image.psd
Literally it's just removing a space for the volume name. There has to be an easy way to scrub through all link paths via script, finding "Our Server" and replace with "OurServer" in link path data. All done right from within the document, not the convoluted way of saving IMDL, fixing and then opening the IMDL file and saving a new document.
I've searched this forum but the scripts are pretty complex and doesn't fit this need exactly.
1 Correct answer
is this any closer?
tell application "Adobe InDesign CC 2018"
tell document 1
set linkList to links
set errInfo to "" -- Displays error if it can't relink an item
-------
repeat with x in linkList
if (x's status) is not normal then -- Checks for broken links only
set linkPath to (x's file path) as string
display dialog 1
-------
set tString to "Volumes:Our Server" as string
if tStr
...Copy link to clipboard
Copied
With a document open, the following has the user choose the new folder where a duplicate of the original linked files will be placed. Then it updates the link information for the image using the duplicated file. It's not bullet proof--I'll leave that up to you. You could have Finder move the file, but I think this is safer. In place of using choose folder, you can set the newFolderPath to a path to the new folder structure.
set folderRef to choose folder
set newFolderPath to folderRef as string
tell application "Adobe InDesign CC 2018"
tell document 1
set linkList to item link of every image of every spline item
repeat with i from length of linkList to 1 by -1
set linkRef to item i of linkList
set origFilePath to file path of linkRef
set fileName to name of linkRef
my copyFile(origFilePath, newFolderPath)
set newFilePath to newFolderPath & fileName
if exists (file newFilePath) then
relink linkRef to file newFilePath
end if
end repeat
end tell
end tell
on copyFile(origFilePath, newFolderPath)
tell application "Finder"
duplicate file origFilePath to newFolderPath
end tell
end copyFile
Copy link to clipboard
Copied
Interesting approach and thank you much for the quick response. It's not 100% what I'm looking for but I will experiment and attempt to modify the script you provided.
Best example, if I didn't explain it correctly is, let's say you had an external drive with thousands of InDesign documents and images. Everything was pointing and linking to the assets on this drive. All is working perfectly however you had to change the name of the external hard drive! Now EVERY link is broken because the link path is different due to only the name change of the external drive. The pathing within that drive are identical, just the name of the volume changed. So, what I was asking for was a simple script that reads/modifies the link paths when the file is open.
The process would go something like:
- Open InDesign File
- Run InDesign script to repair link paths
- Artist preforms any changes/modifications needed
- Command S (save file)
- Close InDesign File
Nothing really changes from the typical procedure but the run script to repair the link paths.
Copy link to clipboard
Copied
Hi,
Assuming the structure does not change under the main volume name, you should be able to do the following.
Current Folder structure: (example)
Current Doc: /Volumes/Our Server/Client/Division/ProjectFolder/Document.indd
Current Link: /Volumes/Our Server/Client/Division/ProjectFolder/Links/image.psd
Future Folder Structure:
Future Doc: /Volumes/OurServer/Client/Division/ProjectFolder/Document.indd
Future Link: /Volumes/OurServer/Client/Division/ProjectFolder/Links/image.psd
If you are using indesign CC/2015/2017/2018 and you have these settings checked
InDesign->Preferences->File Handling
In the Links panel
Make sure
- Check Links Before Opening Document
- Find Missing Links Before Opening Document
Are both checked.
Then just open and save the file, which you can do by script or the next time the document is opened.
The settings above search using a relative path from the document, so as long as the files are in the same relative position they should be found.
Hope this helps
Malcolm
Copy link to clipboard
Copied
I have both of these checked but it still doesn't find the links from a server with a space removed from it. Something so simple but still doesn't repair.
Copy link to clipboard
Copied
is this any closer?
tell application "Adobe InDesign CC 2018"
tell document 1
set linkList to links
set errInfo to "" -- Displays error if it can't relink an item
-------
repeat with x in linkList
if (x's status) is not normal then -- Checks for broken links only
set linkPath to (x's file path) as string
display dialog 1
-------
set tString to "Volumes:Our Server" as string
if tString contains "Volumes:Our Server" then
set AppleScript's text item delimiters to "Volumes:Our Server"
set linkPath to (linkPath's text items) -- Create a list of text items
set AppleScript's text item delimiters to "Volumes:OurServer"
set linkPath to (linkPath as string) -- Concatenate with new path
set AppleScript's text item delimiters to "" -- Reset TIDs
try
relink x to linkPath as alias -- added as alais
try
update x -- This can be helpful
end try
on error err
set errInfo to (errInfo & return & x's name)
end try
end if
end if
end repeat
-------
-- Displays error
if (count errInfo) > 0 then display dialog ("Can't relink:" & errInfo)
end tell
end tell
cheers
Kev
Copy link to clipboard
Copied
YES, YES, YES! Thank you Kevin! Your modification did the trick!
While this script does what I asked, I get a relink error if the server "OurServer" is not mounted. The link path does not update. Is there anyway to force the path change to the new server name even if the server isn't available?
Copy link to clipboard
Copied
would checking in advance to see if "OurServer" is mounted and if not then mount it?
Copy link to clipboard
Copied
Might not be a bad idea as a fail safe. But then again, the users are on the server getting the documents so it should be mounted. I guess the check would be helpful if the documents that needed to updated were on a local machine where there was no reliance on the server.
It's too bad that InDesign doesn't allow the change/saving of the path change via script without requiring a "relink". The relink is failing when the server isn't mounted.
Thank you Kevin for your assistance!
By the way BarlaeDC​, I did a few more tests and in some situations the Auto link update after server name change worked! So thank you for mentioning that to me.
Between the auto link repair built into InDesign and the repair link script, I think we're good! Thank you everyone for your assistance! Much appreciated!
Copy link to clipboard
Copied
toxictool wrote
YES, YES, YES! Thank you Kevin! Your modification did the trick!
While this script does what I asked, I get a relink error if the server "OurServer" is not mounted. The link path does not update. Is there anyway to force the path change to the new server name even if the server isn't available?
Hi toxictool ,
not directly I think.
You could do the trick by exporting the frame to IDMS, editing the link in the IDMS, placing the IDMS and removing the frame holding the original.
Regards,
Uwe
Copy link to clipboard
Copied
Hi,
Just created a new share with a space, and yip, it doesn't work, works if you don't change the space, but removing the space or adding one causes it to fail.
Think that needs to be logged as a bug.
Regards
Malcolm
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I've taken a stab at modifying an Applescript I found in the forums but I'm hitting a snag during the "relink" process. Maybe this will make more sense from a code perspective. There is NO interaction with the end user, this is what I want. Simply open document with broken links, double click script, links are repaired to new server name, done. No pop-ups, no save file, no interaction other than maybe a dialog at end of script saying "Links Repaired!".
tell application "Adobe InDesign CC 2018"
tell document 1
set linkList to links
set errInfo to "" -- Displays error if it can't relink an item
-------
repeat with x in linkList
if (x's status) is not normal then -- Checks for broken links only
set linkPath to (x's file path) as string
-------
if "Volumes:Our Server" is in linkPath then
set AppleScript's text item delimiters to "Volumes:Our Server"
set linkPath to (linkPath's text items) -- Create a list of text items
set AppleScript's text item delimiters to "Volumes:OurServer"
set linkPath to (linkPath as string) -- Concatenate with new path
set AppleScript's text item delimiters to "" -- Reset TIDs
-------
-- I used display dialog to view path at this point. The path is correct with new server location but fails on relink in next step
-- display dialog linkPath
-------
try
relink x to linkPath
try
update x -- This can be helpful
end try
on error err
set errInfo to (errInfo & return & x's name)
end try
end if
end if
end repeat
-------
-- Displays error
if (count errInfo) > 0 then display dialog ("Can't relink:" & errInfo)
end tell
end tell

