Copy link to clipboard
Copied
Every day, I receive files that use varying formats for phone numbers and I have to make them uniform. When I use the find and replace GREP within InDesign below, it works. However, I want to add this to a script I have that makes other normal find and replace statements, so I can do it in one push of the button.
Find what: \(?(\d\d\d)\)?[-. ]?(\d\d\d)[-. ]?(\d\d\d\d)
Change to: $1.$2.$3
______
Right now I have this (below) but it keeps returning this error:
tell application "Adobe InDesign 2024"
set find grep preferences to nothing
set find what of find grep preferences to "(?<(\\d{3}))?[-. ]?(\\d{3})[-., ]?(\\d{4})"
set change grep preferences to nothing
set change grep preferences to find grep preferences -- Set change grep preferences to the same as find grep preferences
set change grep to "$1.$2.$3"
tell active document
set myFoundItems to change grep
end tell
end tell
returns:
Error Number: 30477
Error String: Adobe InDesign 2024 got an error: Invalid value for set property 'change grep preferences'. Expected change grep preference or nothing, but received find grep preference.
_____
This is my other attempt:
tell application "Adobe InDesign 2024"
set find grep preferences to nothing
set find what of find grep preferences to "(?<(\\d{3}))?[-. ]?(\\d{3})[-., ]?(\\d{4})"
set change grep preferences to nothing
set change grep to "$1.$2.$3"
tell active document
set myFoundItems to change grep
end tell
end tell
but I get this error:
Error Number: -10006
Error String: Can't set change grep of "$1.$2.$3" to «script».
----
I am an amateur but I am hoping that someone can help me figure out why this won't work and what will... Thank you.
I like your approach: a script to cleanup a bunch of things at once. That is why I have a Mikes Find/Change by List 2024 available on my website. It cleans up about 30 common typesetting things. I left out phone number cleanup because that is so preferential, but it could be edited in quite easily. Also, I prefer JavaScript over AppleScript, because I prefer cross-platform-ability.
Copy link to clipboard
Copied
Not sure why you want to script this when phone number cleanup is already in the drop-down of the find/change grep panel?
Copy link to clipboard
Copied
To be fair, I had no idea that preset was there. 🙂
Copy link to clipboard
Copied
I am hoping to help my coworker by writing a whole script that does about 8 different cleanup/find/replace commands. This is to help her run one script every morning instead of doing a separate action that she could easily forget. If I an automate it, it would help tremendously.
Copy link to clipboard
Copied
You can use the GREP string in that preset as a model or starting point.
Copy link to clipboard
Copied
Yes, this is where I'm getting the GREP strings, but I think something has to change to make Apple Script understand them. If I paste in the GREP directly, Apple Script chokes on the Syntax error: Expected “"” but found unknown token, when I compile.
GREP: \(?(\d\d\d)\)?[-. ]?(\d\d\d)[-. ]?(\d\d\d\d)
Copy link to clipboard
Copied
error: Expected “"” but found unknown token, when I compile.
GREP: \(?(\d\d\d)\)?[-. ]?(\d\d\d)[-. ]?(\d\d\d\d)
By @Venessa Sylvester
You need to escape certain reserved characters such as ", \ and some other.
The \ character is used for, well, escaping so you need to escape it in the string to indicate that \ is the actual character you wish to use in the string. For example, that's how this string should be passed to AppleScript:
"\\(?(\\d\\d\\d)\\)"
(If you want it to be explained more eloquently, just google "escaping characters in AppleScript").
Copy link to clipboard
Copied
Without going into further details, you can't "set change grep":
"change grep" is a command:
Copy link to clipboard
Copied
Thank you. This is helpful. I changed it to:
set change to of change grep preferences to "$1.$2.$3"
but the whole thing doesn't run at all, even though it compiles after that change.
Copy link to clipboard
Copied
If I have understood the problem, this may help. It works for me.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set FindString to "\\(?(\\d\\d\\d)\\)?[-. ]?(\\d\\d\\d)[-. ]?(\\d\\d\\d\\d)"
set ReplaceString to "$1.$2.$3"
tell application id "com.adobe.InDesign"
set GrepTarget to active document
end tell
RunGrep(GrepTarget, FindString, ReplaceString)
on RunGrep(GrepTarget, FindString, ReplaceString)
tell application id "com.adobe.InDesign"
-- Clear the Find/Change fields
set find grep preferences to nothing
set change grep preferences to nothing
-- Set FindWhat/ChangeTo values
set find what of find grep preferences to FindString
set change to of change grep preferences to ReplaceString
-- Set the find options
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 false
set include locked stories for find of find change grep options to false
tell GrepTarget
change grep
end tell
set find grep preferences to nothing
set change grep preferences to nothing
end tell
end RunGrep
Copy link to clipboard
Copied
I like your approach: a script to cleanup a bunch of things at once. That is why I have a Mikes Find/Change by List 2024 available on my website. It cleans up about 30 common typesetting things. I left out phone number cleanup because that is so preferential, but it could be edited in quite easily. Also, I prefer JavaScript over AppleScript, because I prefer cross-platform-ability.
Copy link to clipboard
Copied
As @Mike Witherell mentioned - maybe you could use Find Change by List script included with InDesign and just add your own "rules"?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now