Skip navigation
Currently Being Moderated

Find / replace within applescript

Apr 13, 2012 3:41 AM

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 smile )

 

Can anyone help we to do this?

 
Replies
  • Currently Being Moderated
    Apr 13, 2012 4:12 AM   in reply to Evilia_77

    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 as:
  • Currently Being Moderated
    Apr 13, 2012 5:54 AM   in reply to Evilia_77

    I showed how to spilt a string in AppleScript… You would have to show me how to make a button in ID for me to test… They don't work all that well with my print/press PDF's

     

    Firstly make sure FilePath is a string/text by…

     

    set ButtonPath to FilePath as string

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 7:12 AM   in reply to Evilia_77

    Did you try what I suggested…? The result of your…

     

    set FilePath to file path of goto anchor behaviors

     

    Is a single item in a list… hence the { }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 7:34 AM   in reply to Evilia_77

    Screen_shot.pngScreen shot 2012-04-13 at 15.20.03.png

     

    Is that what it is supposed to do? linked to another file in another folder?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 11:17 AM   in reply to Evilia_77

    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 as:
  • Currently Being Moderated
    Apr 13, 2012 11:54 AM   in reply to Evilia_77

    Your English is better than my interactive ID skills… I'm guess Im lucky scripting languages are mostly american/english ( is that right anyone I've no idea? ) or I'd be up a creek with no paddle… Yes the linked doc changed as the pic showed and the document was modified* in the menubar…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 2:19 PM   in reply to Evilia_77

    It seems to be missing the final command you need. You've done all the slicing, dicing, and putting the string back together. Now you just need to tell it to use that string somewhere:

     

      set file path of goto anchor behaviors to NewPath


     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 3:07 AM   in reply to Evilia_77

    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 as:
  • Currently Being Moderated
    Apr 16, 2012 4:30 AM   in reply to Evilia_77

    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 as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points