Hello, I’m not able to compile the script below. (Syntax eror Expected “” but found unknown token). It is not a complicated search but can’t get it to work. Would love an explanation if possible where my error resides
Need to perform 2 GREP finds.
Example 1 :
$1.99 5.99 $189.99 599.99. I know in Indesign the $ symbol is problematic so in the Find/change/Grep i’m using the unicode value. This GREP search works perfect but not in the script. \x{0024}?[\d.]+\d{2}. I found that I needed to add an xtra \ to the digits but still i’m not able to compiling it \x{0024}?[\d.]+\d{2}
Example 2:
Find a pattern & replace with a tab
Tab (might be there or not)
Find literal 120
followed by 2 uppercase letters
followed 5 digits
after the 5 digits (uppercase |or digits) might be there or not
example codes: 120AB12345, 120BC78945CD788, 120BC15935ABCL
See below
tell application "Adobe InDesign CS4"
--Clear the Find/Change fields
set find text preferences to nothing
set change text preferences to nothing
--Set FindWhat
set find what of find grep preferences to "\x{0024}?[\\d.]+\\d{2}"
--The $ symbol (unicode \x{0024}) might be there or not
set change to of change grep preferences to "" --replace with nothing
set find what of find grep preferences to "\t?120[\u]{2}[\d]{5}([\u|\d]+)?"
set change to of change grep preferences to "\t" --replace with a tab
--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
--Do It
change grep
set find grep preferences to nothing
set change grep preferences to nothing
end tell
Hi. I notice there is only one actual change for two patterns, themselves possibly too verbose. The GREP options can all be changed at once and, if they are nothing, you don’t have to use an empty string as a replacement. Brace the dollar sign.
tell application "Adobe InDesign CS3"
set {find grep preferences, change grep preferences} to {nothing, nothing}
set find change grep options's properties to {include footnotes:0, include hidden layers:0, include locked layers for find:0, include locked stories for find:0, include master pages:0}
# OPTIONAL dollar sign & any NUMBERS, PERIOD with MANDATORY trailing numbers, avoiding lookahead
set find what of find grep preferences to "[$]?\\d+[.]\\d{2}(?! OZ)"
change grep
# OPTIONAL tab & LITERAL 120 w/ whatever trailing it
set find what of find grep preferences to "^120\\w+"
set change to of change grep preferences to tab
change grep
end tell
Thanks kel. That compiled but I realize that the grep expresion for the prices is finding things that are not prices like for example 2.90 oz which technically matches x{0024}?[\d,]+\.\d{2}. i’m trying to figure it out a way not to find a space followed by any character
As always Thanxs Marc,
the expression [ ]?120.+ is deleting everything that follows it. The 1st column needs to be replaced with a tab. The columns with pricing needs to deleted. Also the 2.99 OZ has been changed because it falls in the expression “[$]?[\d]+[.]+\d{2}” but it is not a price
120AM81553 L 10/BX $32.09 $30.39 $28.59
120AM81553 L 10/BX 32.09 30.39 1.99
120VM91451AB L 2.99 OZ 22.09 21.89 200.59
It looks like the bug isn’t in the dollar sign symbology, but is isolated to the preferences”specifically the find change grep options that I initially recommended to set as nothing, to shorten the code. :rolleyes:
The dictionary states this is an acceptable option, but it makes ID’s grep randomly lose the ability to find some patterns until the app is restarted. I’m not sure which versions are affected, but you should be able to reliably use the edited code.
BAD:
set {find grep preferences, change grep preferences, find change grep options} to {nothing, nothing, nothing}
I’m not sure how to handle that, as I don’t use the POSIX format”the self-similarity in that example hurts my eyes. The snippet works on my end, but there are apparent differences in the search terms, as the result is different.
This is returned with the POSIX version:
120AM81553 L 10/BX
120AM81553 L 10/BX 1.99
120VM91451AB L 2.99 OZ 2
vs. this with [$]?\d+[.]\d{2}(?! OZ)
120AM81553 L 10/BX
120AM81553 L 10/BX
120VM91451AB L 2.99 OZ
I have to accept that using POSIX can hurt anybody eyes. I hope you don’t get mad but why is this is not finding anything
tell application "Adobe InDesign CS4"
set {find grep preferences, change grep preferences} to {nothing, nothing}
set find change grep options's properties to {include footnotes:0, include hidden layers:0, include locked layers for find:0, include locked stories for find:0, include master pages:0}
set find what of find grep preferences to "[$]?\\d+[.]\\d{2}"
set change to of change grep preferences to tab
change grep
end tell
That works fine for me, however, I’m using CS3 on Mavericks. I’m also running the script from AppleScript Editor. Restart inDesign and verify that you’re able to do a manual search of the pattern without the escaped \d; i.e. [$]?\d+[.]\d{2}
As always Marc you were right. I restarted in InDesign & it worked.
I found another wall. I realized if have some documents open & run the script all open documents are changing. How can I run it only on the current active document.
tell application "Adobe InDesign CS4"
set activeDocument to active document
set {find grep preferences, change grep preferences} to {nothing, nothing}
set find change grep options's properties to {include footnotes:0, include hidden layers:0, include locked layers for find:0, include locked stories for find:0, include master pages:0}
-- [\\t~S]+ means find any sequence of Space, Tab, or Fixed Space, ad inifitum.
# OPTIONAL? dollar sign & any NUMBERS, PERIOD with NUMBER (2 digits), avoiding lookahead-->(?! ) avoid to search for 11.90 oz, 55.60 liters etc
set find what of find grep preferences to "[$]?\\d+[.]\\d{2}(?! .+)"
change grep
set find what of find grep preferences to "[\\t~S]+?[$]?\\d+[.]\\d{2}(?! .+)"
change grep
--OPTIONAL tab & LITERAL 120
set find what of find grep preferences to "\\t?120[\\u]{2}[\\d]{5}([\\u|\\d]+)?"
--set change to of change grep preferences to tab
set change to of change grep preferences to "\\t\\t"
change grep
end tell