Skip to main content
Inspiring
August 1, 2019
Answered

Help! AppleScript GREP Find and Delete

  • August 1, 2019
  • 2 replies
  • 1074 views

I have a large InDesign document that is being data merged. The result is a frame left with this GREP: \s\s\|\s\s\r\,\s\n\,\s. Can someone help me with an AppleScript that will find that GREP, replace with nothing and leave just an empty text box? I can do it as a Find/Change, but I'm hoping to automate it with a script.

Any help would be greatly appreciated!! Thanks!

This topic has been closed for replies.
Correct answer Sunil Yadav

Try this code for your reference:

tell application "Adobe InDesign CS6"

  set Reset to 0

  repeat while Reset is equal to 0

  set find grep preferences to nothing

  set change grep preferences to nothing

  set include footnotes of find change grep options to false

  set include hidden layers of find change grep options to false

  set include locked layers for find of find change grep options to true

  set include locked stories for find of find change grep options to true

  set include master pages of find change grep options to false

  set find what of find grep preferences to "~b~b+"--Here you can put your grep whatever you want to put--I have found multiple enter and replace them with nothing

  set findList to find grep

  set Reset to 1

  set findListCnt to count of findList

  repeat with i from findListCnt to 1 by -1

  select item i of findList

  tell active document

  clear overrides selection

  delete first character of selection

  clear overrides selection

  end tell

  set Reset to 0

  end repeat

  set find grep preferences to nothing

  set change grep preferences to nothing

  end repeat

end tell

Take the logic and manipulate the code for your need!!!

Best

Sunil

2 replies

Inspiring
August 6, 2019

This is the final script I ended up using. I ended up changing this line:

delete first character of selection

to

delete (every character of selection)

tell application "Adobe InDesign CC 2019"

  set Reset to 0

  repeat while Reset is equal to 0

  set find grep preferences to nothing

  set change grep preferences to nothing

  set include footnotes of find change grep options to false

  set include hidden layers of find change grep options to false

  set include locked layers for find of find change grep options to true

  set include locked stories for find of find change grep options to true

  set include master pages of find change grep options to false

  set find what of find grep preferences to "\\s\\s\\|\\s\\s\\r\\,\\s\\n\\,\\s" --Enter GREP Search 

  set findList to find grep

  set Reset to 1

  set findListCnt to count of findList

  repeat with i from findListCnt to 1 by -1

  select item i of findList

  tell active document

  clear overrides selection

  delete (every character of selection)

  clear overrides selection

  end tell

  set Reset to 0

  end repeat

  set find grep preferences to nothing

  set change grep preferences to nothing

  end repeat

end tell

Sunil Yadav
Sunil YadavCorrect answer
Legend
August 2, 2019

Try this code for your reference:

tell application "Adobe InDesign CS6"

  set Reset to 0

  repeat while Reset is equal to 0

  set find grep preferences to nothing

  set change grep preferences to nothing

  set include footnotes of find change grep options to false

  set include hidden layers of find change grep options to false

  set include locked layers for find of find change grep options to true

  set include locked stories for find of find change grep options to true

  set include master pages of find change grep options to false

  set find what of find grep preferences to "~b~b+"--Here you can put your grep whatever you want to put--I have found multiple enter and replace them with nothing

  set findList to find grep

  set Reset to 1

  set findListCnt to count of findList

  repeat with i from findListCnt to 1 by -1

  select item i of findList

  tell active document

  clear overrides selection

  delete first character of selection

  clear overrides selection

  end tell

  set Reset to 0

  end repeat

  set find grep preferences to nothing

  set change grep preferences to nothing

  end repeat

end tell

Take the logic and manipulate the code for your need!!!

Best

Sunil

Inspiring
August 6, 2019

Thank you so much, Sunil!! I really, REALLY appreciate it!