Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script and GREP/Find/Change

Tagged: ,

Return to Member Forum

  • Author
    Posts
    • #96739
      Bob Rubey
      Member

      I located a script that might come in handy for some of my work: https://www.scriptopedia.org/en/js-indesign/189-find-change-links-in-indesign.html

      I didn’t have a problem with Find/Change Text Option when I tested, but the GREP combinations I try always result in No Matching File Found and it is the GREP option that I am more likely to need. For my purposes, filename.tif (and other file types) will always be replaced with filename_00A.tif (underscore, two digits, and a cap letter).

      This is where I am at…
      Find what:
      \.tif
      Replace with:
      \dd\u\ .tif

      I’ve tried changing \dd\ to \d{2}\ and bracketing with as well as removing the space before .tif but nothing has worked and GREP is not something I’ve used before.

      Bob

    • #96747
      Peter Kahrel
      Participant

      Maybe you should give some examples of what you want to do. Your find and replace string don’t make a lot of sense: you search for \.tif and replace that with \dd\u\.tif — which means that a string like screen.tif is replaced with screen\dd\u\.tif

    • #96748
      Bob Rubey
      Member

      Thanks for looking Peter.

      I’m just trying to adjust for my workflow following the examples on the scriptopedia.org website (see original post).

      Once the GREP parameters are entered, instead of using the Find/Change search options the script is started. I’ve never received an error from the script, but it never finds matching files either.

      I thought my original post was clear, but here’s what happens…
      Image files are received (filename.tif, filename.jpg, and so on).
      Image files are edited and finished files are (usually) saved as tif are given a suffix (filename_00A.tif). The suffix is always (underscore, two digits, and a cap letter).

      I would like the script to replace the original files (sans suffix) with the new files.

      Bob

    • #96780
      Peter Kahrel
      Participant

      Sorry, Bob, I should have looked better. I think the problem is that you use \u in JavaScript GREP — it doesn’t exist. Instead, use [A-Z] to test for capital letter, e.g.

      if (/_\d\d[A-Z](?=\.tif$)/.test (f[i].name))

      P.

    • #96781
      Bob Rubey
      Member

      Peter,

      I wondered if something like that might be the problem when I realized there were no Wildcards under @ in the Change to:. The demo only shows Wildcards in the Find what: field.

      So, as an experiment I re-saved both sets of images as JPEGs (in case the script didn’t work with other formats) and followed the Demo example exactly. Unfortunately it never found matching files no matter what I did with GREP.

      I’ve pretty much given up on GREP when it comes to the script. I haven’t had any problems using the Text option, and perhaps it would be wise to replace images in smaller batches anyway ; ). And I won’t need the script often.

      It was still a good/interesting introduction to GREP and maybe I will find another need/use for it in the future.

      Thanks for your help!

      Bob

    • #96818
      Graham Park
      Member

      Bob
      I would try a simple GREP script as below. This will find the filenames in the format you have listed, remove the suffix and change the extension to .tif from .jpg
      Will only work when the suffix is an underscore followed but two digits and an uppercase letter and the .jpg
      If you don’t want to change the extension

      Find
      (.+)_\d{2}[\u].jpg
      Replace
      $1.tif

      If you don’t want to change the extension then
      Find
      (.+)_\d{2}[\u](.jpg)
      Change
      $1$2

      Graham

Viewing 5 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads