I am working on a script to change the file path of a hyperlink
tell application "Adobe InDesign CS5"
tell active document
set listOfButtons to every button
repeat with thisButton in listOfButtons
tell thisButton
set FilePath to file path of goto anchor behaviors
return FilePath
end tell
end repeat
end tell
end tell
the answer I get is : {"Content:Pricelist:Catalog:Interactief:BE:21_ES_Ventielen_be_dig.ind d"}
Now I want to change "BE" into "FR" and "be" into "fr"
(in the future I will have to change it to other suffix, so it would be nice if this can be included as well
)
Can anyone help we to do this?
Here is one way that should show how to break the path string down to sub strings… That you can manipulate…
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to "Content:Pricelist:Catalog:Interactief:BE:21_ES_Ventielen_be_dig.indd "
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
-- Result: {"Content", "Pricelist", "Catalog", "Interactief", "BE", "21_ES_Ventielen_be_dig.indd"}
set NewPath to items 1 thru 4 of PathBits & "FR:" as text -- Compile the sting white still ":"
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of the last item of PathBits -- Slice it…
-- Result: {"21", "ES", "Ventielen", "be", "dig.indd"}
set NewPath to NewPath & (items 1 thru 3 of DocBits & "fr" & last item of DocBits) as text -- Compile the sting white still "_"
-- Result: "Content:Pricelist:Catalog:Interactief:FR:21_ES_Ventielen_fr_dig.indd "
set AppleScript's text item delimiters to ASTID -- Restore settings
Mark,
I tried this:
tell application "Adobe InDesign CS5"
tell active document
set listOfButtons to every button
repeat with thisButton in listOfButtons
tell thisButton
set FilePath to file path of goto anchor behaviors
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to FilePath
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
-- Result: {"Content", "Pricelist", "Catalog", "Interactief", "BE", "21_ES_Ventielen_be_dig.indd"}
set NewPath to items 1 thru 4 of PathBits & "FR:" as text -- Compile the sting white still ":"
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of the last item of PathBits -- Slice it…
-- Result: {"21", "ES", "Ventielen", "be", "dig.indd"}
set NewPath to NewPath & (items 1 thru 3 of DocBits & "fr" & last item of DocBits) as text -- Compile the sting white still "_"
-- Result: "Content:Pricelist:Catalog:Interactief:FR:21_ES_Ventielen_fr_dig.indd "
set AppleScript's text item delimiters to ASTID -- Restore settings
end tell
end repeat
end tell
end tell
I get a error on splitting the path. This is the answer I get, after asking to return "PathBits" : {"Content:Pricelist:Catalog:Interactief:BE:21_ES_Ventielen_be_dig.ind d"}
what am I doing wrong?
Mark,
How te make a button in ID:
1) make a rectangle
2) convert the rectangle to a button (Menu\Object\Interactive\convert to button)
3) go to menu\Window\Interactive\Buttons you get the buttons menu.
4) there you can give some actions. I used "go to destination". The path I choose there, is the path I want to change by this script.
I hope this will help you to help me .. ![]()
Mark,
I could arrange that the script does what I want.. (changing the filepath) Or I think I did...
this is the script:
tell application "Adobe InDesign CS5"
tell active document
set listOfButtons to every button
repeat with thisButton in listOfButtons
tell thisButton
set FilePath to file path of goto anchor behaviors
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to (item 1 of FilePath)
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
-- Result: {"Content", "Pricelist", "Catalog", "Interactief", "BE", "21_ES_Ventielen_be_dig.indd"}
set NewPath to items 1 thru 4 of PathBits & "FR:" as text -- Compile the sting white still ":"
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of the last item of PathBits -- Slice it…
-- Result: {"21", "ES", "Ventielen", "be", "dig.indd"}
set NewPath to NewPath & (items 1 thru 3 of DocBits & "fr" & last item of DocBits) as text -- Compile the sting white still "_" as string
-- Result: "Content:Pricelist:Catalog:Interactief:FR:21_ES_Ventielen_fr_dig.indd "
set AppleScript's text item delimiters to ASTID -- Restore settings
set file path of goto anchor behaviors to NewPath
end tell
end repeat
end tell
end tell
this is the answer I get
tell application "Adobe InDesign CS5"
get every button of active document
--> {button id 211 of spread id 185 of document id 161, button id 200 of spread id 185 of document id 161}
get file path of every goto anchor behavior of button id 211 of spread id 185 of document id 161
--> {"Content:Pricelist:Catalog:Interactief:BE:21_ES_Ventielen_be_dig.indd "}
set file path of every goto anchor behavior of button id 211 of spread id 185 of document id 161 to "Content:Pricelist:Catalog:Interactief:FR:21_ES_Ventielen_fr_dig.indd "
get file path of every goto anchor behavior of button id 200 of spread id 185 of document id 161
--> {"Content:Pricelist:Catalog:Interactief:BE:21_ES_Ventielen_be_dig.indd "}
set file path of every goto anchor behavior of button id 200 of spread id 185 of document id 161 to "Content:Pricelist:Catalog:Interactief:FR:21_ES_Ventielen_fr_dig.indd "
end tell
as you can see the script changed the filepath, but in the Indesign document the path didn't change.. ![]()
Evilia_77, Im trying to second guess what it is you want. I don't deal with this in the line of work I use ID for… ( although Im sure that will change one day ) The screen shots posted were what I got while at my work mac ( not the slightest clue if thats right? ) Both the file and its parent directory changed locale? I don't think ( eek ) what you are trying to do is taxing in either AppleScript or JavaScript but you cloud the waters with mulit posts in differing scripting languages… You cut your chances of help here right down with AppleScript… ( mine's rusty ) Im guessing at your process…
with active book
get list of locale folders from a given directory
loop locale's
loop the book documents
open each doc
loop links replacing locale string
loop buttons replacing locale string
save
close
update book?
export each to interactive PDF?
done…
Mark,
I think the problem is that my english is very bad, and that my applescript skills are very bad.
We are making an interactive catalogue, where you can jump from one chapter to an other one. The native one (dutch) is ready and works fine. For making the French catalogue, I copied the Dutch one and translate the documents. The buttons in the French version are linked to the dutch document. Thats why I want to make the script to change the file path.
The script you made changes the paths but when I check the buttons in the indesign document, the still are linked to the ducht versions.
Does the script works on your mac, does is changes the destinations of the buttons in the indesign doc?
Mark,
thank you very much... I tried and tried in the office, and it didn't change... but it is possible that it's due to our servers (we work only on servers so we can work all togehter on the catalogue).. the connection isn't so well..
I will try it again on monday and I hope it works... it will save me weeks of work ![]()
Hopefully I can tell you on monday some good news
G'day
I tested the script you and Mark developed today. I'm in CS5.5 and the only thing I needed to change was "...as text" to "...as string" wherever it occured (otherwise it wouldn't compile).
tell application "Adobe InDesign CS5.5"
tell active document
set listOfButtons to every button
repeat with thisButton in listOfButtons
tell thisButton
set FilePath to file path of goto anchor behaviors
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to (item 1 of FilePath)
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
-- Result: {"Content", "Pricelist", "Catalog", "Interactief", "BE", "21_ES_Ventielen_be_dig.indd"}
set NewPath to items 1 thru 4 of PathBits & "FR:" as string -- Compile the sting white still ":"
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of the last item of PathBits -- Slice it…
-- Result: {"21", "ES", "Ventielen", "be", "dig.indd"}
set NewPath to NewPath & (items 1 thru 3 of DocBits & "fr" & last item of DocBits) as string -- Compile the sting white still "_" as string
-- Result: "Content:Pricelist:Catalog:Interactief:FR:21_ES_Ventielen_fr_dig.indd "
set AppleScript's text item delimiters to ASTID -- Restore settings
set file path of goto anchor behaviors to NewPath
end tell
end repeat
end tell
end tell
The script worked perfectly (however, I only tested in a one page file with a single button — not sure if that makes any difference).
The destination link changed to the fr version in FR folder — and I could just as easily change it back again.
I really have no suggestion why it would work on my machine and not yours — but hopefully this information is helpful to you.
Best of luck to you
m.
Mark,
I had to change the final command to
set file path of goto anchor behaviors of thisButton to NewPath
I changed the script a little bit because I noticed that "to items 1 thru 4" didn't work on all the files
this is the new script:
tell application "Adobe InDesign CS5"
tell active document
set listOfButtons to every button
repeat with thisButton in listOfButtons
tell thisButton
set FilePath to file path of goto anchor behaviors
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to (item 1 of FilePath) as string
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
repeat with i from 1 to count PathBits
considering case
if item i of PathBits is "NL" then
set item i of PathBits to "FR"
end if
end considering
end repeat
set TempPath to items 1 thru i of PathBits as string
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of TempPath
repeat with j from 1 to count DocBits
considering case
if item j of DocBits is "nl" then
set item j of DocBits to "fr"
end if
end considering
end repeat
set NewPath to items 1 thru j of DocBits as string
set file path of goto anchor behaviors of thisButton to NewPath
end tell
end repeat
end tell
end tell
Now I just have to make it possible to do this for all the buttons in a document. First I want to make it possible to choose the original path and doc...
This is what I've got at this moment:
tell application "Adobe InDesign CS5"
tell active document
--choose path
set PathOrigArray to {"BE", "FR", "NL", "EX", "DE"}
set PathOrigID to choose from list PathOrigArray with prompt "Selecteer de map met originele bestanden." OK button name "Update book" without multiple selections allowed
set PathNewArray to {"FR", "NL", "EX", "DE"}
set PathNewID to choose from list PathNewArray with prompt "Selecteer de map met nieuwe bestanden." OK button name "Update book" without multiple selections allowed
--choose doc
set DocOrigArray to {"be", "fr", "nl", "ex", "de"}
set DocOrigID to choose from list DocOrigArray with prompt "Selecteer de suffix van de originele bestanden." OK button name "Update book" without multiple selections allowed
set DocNewArray to {"fr", "nl", "ex", "de"}
set DocNewID to choose from list DocNewArray with prompt "Selecteer de suffix van de nieuwe bestanden." OK button name "Update book" without multiple selections allowed
set listOfButtons to every button
repeat with thisButton in listOfButtons
tell thisButton
set FilePath to file path of goto anchor behaviors
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to (item 1 of FilePath) as string
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
repeat with i from 1 to count PathBits
considering case
if item i of PathBits is PathOrigID then
set item i of PathBits to PathNewID
end if
end considering
end repeat
set TempPath to items 1 thru i of PathBits as string
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of TempPath
repeat with j from 1 to count DocBits
considering case
if item j of DocBits is DocOrigID then
set item j of DocBits to DocNewID
end if
end considering
end repeat
set NewPath to items 1 thru j of DocBits as string
set file path of goto anchor behaviors of thisButton to NewPath
end tell
end repeat
end tell
end tell
The problem is that he doesn't change the items... what I am doing wrong?
I had to change the final command to
set file path of goto anchor behaviors of thisButton to NewPath
Hum, I used the same as Mary & Dwayne… That line is inside of a tell thisButton block so shouldn't be needed… Yes I would expect 1 thru 4 needs to change I only coded it as per your example… I only have CS5 but it works fine here…
String & text in AppleScript are the same thing Dwayne's issue in CS5.5 may be down to a clash with ID's reference to the text class… ( I didn't get that here though )
Mark,
we did it.. this script works for a book but isn't perfect. To make it perfect I just have to do
1) open a document without the question 'update links'
2) choose the original path and doc (BE - be) and choose the new path and doc (ex. FR-fr or NL-nl)
I don't know if it is possible to include those commands.. If anyone knows how.. please help me
tell application "Adobe InDesign CS5"
activate
if active book exists then
else
set GetParentPath to ((choose file with prompt "Kies een Indesignbook:"))
open GetParentPath
delay 1
end if
end tell
tell application "Adobe InDesign CS5"
tell active book
set fileList to full name of book contents
end tell
repeat with aFile in fileList
set theDoc to open aFile
set myDocument to active document
tell myDocument
set listOfButtons to every button
repeat with k from 1 to count listOfButtons
set thisButton to button k
tell thisButton
try
set FilePath to file path of goto anchor behaviors
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to (item 1 of FilePath) as string
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
repeat with i from 1 to count PathBits
considering case
if item i of PathBits is "BE" then
set item i of PathBits to "NL"
end if
end considering
end repeat
set TempPath to items 1 thru i of PathBits as string
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of TempPath
repeat with j from 1 to count DocBits
considering case
if item j of DocBits is "be" then
set item j of DocBits to "nl"
end if
end considering
end repeat
set NewPath to items 1 thru j of DocBits as string
set file path of goto anchor behaviors of thisButton to NewPath
end try
end tell
end repeat
close theDoc saving yes
end tell
end repeat
display dialog "De documenten zijn aangepast"
end tell
For all who is interested.. .this is the complete script
tell application "Adobe InDesign CS5"
--choose path & doc
set PathOrigArray to {"BE", "FR", "NL", "EX", "DE"}
set PathOrigID to choose from list PathOrigArray with prompt "Selecteer de map met originele bestanden." OK button name "Update book" without multiple selections allowed
if PathOrigID is "false" then return
set DocOrigArray to {"be", "fr", "nl", "ex", "de"}
set DocOrigID to choose from list DocOrigArray with prompt "Selecteer de suffix van de originele bestanden." OK button name "Update book" without multiple selections allowed
if DocOrigID is "false" then return
set PathNewArray to {"FR", "NL", "EX", "DE"}
set PathNewID to choose from list PathNewArray with prompt "Selecteer de map met nieuwe bestanden." OK button name "Update book" without multiple selections allowed
if PathNewID is "false" then return
set DocNewArray to {"fr", "nl", "ex", "de"}
set DocNewID to choose from list DocNewArray with prompt "Selecteer de suffix van de nieuwe bestanden." OK button name "Update book" without multiple selections allowed
if DocNewID is "false" then return
set oldParam to check links at open of linking preferences
set check links at open of linking preferences to false
activate
if active book exists then
else
set GetParentPath to ((choose file with prompt "Kies een Indesignbook:" of type "IDb5.5"))
open GetParentPath
delay 1
end if
end tell
tell application "Adobe InDesign CS5"
tell active book
set fileList to full name of book contents
end tell
repeat with aFile in fileList
set theDoc to open aFile
set myDocument to active document
tell myDocument
--change destination
set listOfButtons to every button
repeat with k from 1 to count listOfButtons
set thisButton to button k
tell thisButton
try
set FilePath to file path of goto anchor behaviors
set ASTID to AppleScript's text item delimiters -- Store settings
set ButtonPath to (item 1 of FilePath) as string
set AppleScript's text item delimiters to ":" -- Everything splits at this character
set PathBits to text items of ButtonPath -- Slice it…
repeat with i from 1 to count PathBits
log item i of PathBits
log PathOrigID
if (item i of PathBits) as string is equal to PathOrigID as string then
set item i of PathBits to PathNewID
end if
end repeat
set TempPath to items 1 thru i of PathBits as string
--log "TempPath " & TempPath
set AppleScript's text item delimiters to "_" -- Now everything splits at this character
set DocBits to text items of TempPath -- Slice it…
repeat with j from 1 to count DocBits
if (item j of DocBits) as string is DocOrigID as string then
set item j of DocBits to DocNewID
end if
end repeat
set NewPath to items 1 thru j of DocBits as string -- set new path
set file path of goto anchor behaviors of thisButton to NewPath --asign new path to button
end try
end tell
end repeat
close theDoc saving yes
end tell
end repeat
display dialog "De documenten zijn aangepast"
set check links at open of linking preferences to oldParam
end tell
North America
Europe, Middle East and Africa
Asia Pacific