Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


grep prices & pattern applescript

Community Beginner ,
Aug 19, 2014 Aug 19, 2014

Copy link to clipboard

Copied

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. I also tried the FindChangebyList applescript but I'm having unknown token  error  too

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

tell application "Adobe InDesign CS4"

  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}"

  --Find $1.99, $11.99, $119.99, 1599.99 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  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

change grep

  set find grep preferences to nothing

  set change grep preferences to nothing

end tell

TOPICS
Scripting

Views

780

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Aug 20, 2014 Aug 20, 2014
Hi,first of all, I have no idea how to write an applescript . So this is my first one.Some thoughts:1. If you escape something, you must escape it in general, so not only digits, but also \x{0024} or \t  >> \\x and \\t2. If you have two queries, you must set 'change grep' twice3. Some cosmetics: \x{0024} can be written as \x24 and [\d]{5} should be written als \d{5}.With some changes, this lines work for me: tell application "Adobe InDesign CC 2014"         set find grep preferences to nothing ...

Likes

Translate

Translate
Enthusiast ,
Aug 20, 2014 Aug 20, 2014

Copy link to clipboard

Copied

Hi,

first of all, I have no idea how to write an applescript . So this is my first one.

Some thoughts:

1. If you escape something, you must escape it in general, so not only digits, but also \x{0024} or \t  >> \\x and \\t

2. If you have two queries, you must set 'change grep' twice

3. Some cosmetics: \x{0024} can be written as \x24 and [\d]{5} should be written als \d{5}.

With some changes, this lines work for me:

tell application "Adobe InDesign CC 2014"

   

    set find grep preferences to nothing

    set change grep preferences to nothing

   

   

    set find what of find grep preferences to "\\x24?\\d+\\.\\d{2}"

    set change to of change grep preferences to "" --replace with nothing   

    change grep

   

   

    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       

    change grep

   

    set find grep preferences to nothing

    set change grep preferences to nothing

   

end tell

– Kai

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 20, 2014 Aug 20, 2014

Copy link to clipboard

Copied

Thanks Kai. I'm trying a different approach. I'm using POSIX classes for finding $ & the prices. When I'm using the Find & Change windowThe code is compiling but it's not finding anything. Do i need escape characters too. If that's the case where I should put the escape character \\

tell application "Adobe InDesign CS4"

  set find text preferences to nothing

  set change text preferences to nothing

--Set FindWhat

  set find what of find grep preferences to "~h?[[=$=]]?[[:digit:]][[:digit:]][[=.=]][[:digit:]][[:digit:]]"

  --Find $11.99, The $ symbol 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  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

change grep

  set find grep preferences to nothing

  set change grep preferences to nothing

end tell

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2021 Jul 10, 2021

Copy link to clipboard

Copied

Is it free to play

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

LATEST

If you mean 'Can I use this script?' then yes, any script that's posted here is free for you to use.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines