Copy link to clipboard
Copied
Hi all,
I've been trying to dig around for a script that would let me add a prefix to all the linked files in an InDesign doc, but let me specify the prefix each time.
So a document with the following links:
Edward Clarke_this file.tif
David Smith_another file.tif
Steve Irwin_yet another one.tif
...could be renamed and relink the files to:
1499_Edward Clarke_this file.tif
1499_David Smith_another file.tif
1499_Steve Irwin_yet another one.tif
or any other number I might specify on that occasion via an input box.
The scripts by Kasyan Servetsky seem to come closest to what I'm trying to do, but my scripting knowledge is non-existent (i can cobble together some pretty childlike css and html), so although I can just about follow what is going on I wouldn't know where to start when it comes to adapting it.
Would anyone be prepared to give me some pointers on how to do it? It would save my friends an insane amount of time every week...
All the best,
Ed
I have the script written for AppleScript (assuming you are working with Macintosh). It would be slightly more difficult to write it for JavaScript since it needs to work with the system (Windows or Mac).
set preName to "123_"
set pathList to {}
tell application "Adobe InDesign CC 2019"
tell document 1
set linkList to links
repeat with i from 1 to length of linkList
set thisLink to item i of linkList
set end of pathList to {name of thisLink, file path of thisLink}
end repeat
end tell
end tell
--change name
...Copy link to clipboard
Copied
I have the script written for AppleScript (assuming you are working with Macintosh). It would be slightly more difficult to write it for JavaScript since it needs to work with the system (Windows or Mac).
set preName to "123_"
set pathList to {}
tell application "Adobe InDesign CC 2019"
tell document 1
set linkList to links
repeat with i from 1 to length of linkList
set thisLink to item i of linkList
set end of pathList to {name of thisLink, file path of thisLink}
end repeat
end tell
end tell
--change name of file
repeat with j from 1 to length of pathList
set thisFile to (item 2 of item j of pathList)
set oldName to item 1 of item j of pathList
try
tell application "Finder"
set name of file thisFile to preName & oldName
end tell
end try
end repeat
tell application "Adobe InDesign CC 2019"
tell document 1
repeat with k from 1 to length of pathList
set oldLink to item k of pathList
set oldPath to item 2 of oldLink
set linkRef to link (item 1 of oldLink)
if status of linkRef is link missing then
set newPath to my getnewPath(oldPath, preName)
set aliasRef to newPath as alias
try
tell linkRef
relink to aliasRef
end tell
end try
end if
end repeat
end tell
end tell
--gets new file path from old file path
on getnewPath(oldLink, preName)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pathItems to text items of oldLink
set oldName to item -1 of pathItems
set item -1 of pathItems to preName & oldName
set newPath to pathItems as text
set AppleScript's text item delimiters to ""
return newPath
end getnewPath
Copy link to clipboard
Copied
Thank you so much for taking a look at this for me!
I am indeed on a mac, so applescript will be perfect.
I need to get back in front of my machine at work to put this in, but this is incredibly kind of you to help me out.
On a side note: I know even less about applescript than JavaScript, but from the code you've given me it sure looks easier to digest than JavaScript. I may have to settle down with some tutorials and get my head around it
Thanks again!
Copy link to clipboard
Copied
S Hopkins, you're an absolute star, that worked perfectly!
It also forced me to get off my lazy backside and learn something, so, after some digging around, I decided to change your opening 'set preName' bit to the following so that we can vary the prefix from issue to issue:
display dialog "Please enter the issue number" default answer ""
set the preName to the text returned of the result & "_"
Thank you so much, this is going to be brilliant
All the best,
Ed
Copy link to clipboard
Copied
I am a windows user and I am wondering if there is a .jsx script that does the same job thanks a lot!!!