• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Run Applescript on Selection/Story/Document

Explorer ,
Jul 31, 2018 Jul 31, 2018

Copy link to clipboard

Copied

Hi all

Is it possible to tell an Applescript to run on the selected text only? If so, please tell me how!

My script (condensed version):

tell application "Adobe InDesign CC 2018"

 

  my GrepSearch("(January|February|March|April|May|June|July|August|September|October|November|December) (\\d{1}|\\d{2}), (\\d{4})")

  my GrepSearch("(January|February|March|April|May|June|July|August|September|October|November|December) (\\d{4})")

end tell

on GrepSearch(f)

  tell application "Adobe InDesign CC 2018"

  set find grep preferences to nothing

  set change grep preferences to nothing

  set find what of find grep preferences to f

  set no break of change grep preferences to true

  change grep

  end tell

end GrepSearch

(searching for date strings and telling ID to apply No Break character attribute to the strings)

Thank you in advance!

TOPICS
Scripting

Views

948

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
Engaged ,
Aug 01, 2018 Aug 01, 2018

Copy link to clipboard

Copied

Well, it's been a long time since I've written any AppleScript, but the javascript syntax looks like this:

app.selection[0].changeGrep;

(which assumes that the user has selected some text beforehand. always a good idea to test that)

In your script, the "change grep" line is within a "tell application" block, which gives it a broad scope. Your solution will be something like:

tell selected text

     change grep

end tell

Or maybe it's "tell selection"?

Bob

Votes

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
Contributor ,
Aug 02, 2018 Aug 02, 2018

Copy link to clipboard

Copied

Something like this (as Rob mentioned, best to test if you have selected text first)

tell application "Adobe InDesign CC 2018"

          set mySelection to selection

                   tell mySelection

                             set myFoundItems to change grep

                   end tell

end tell

Votes

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
Engaged ,
Aug 03, 2018 Aug 03, 2018

Copy link to clipboard

Copied

"Selection"! I do miss Applescript.

Votes

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
Enthusiast ,
Aug 04, 2018 Aug 04, 2018

Copy link to clipboard

Copied

Be careful. Remember selection returns a list and can return a number of item types. Check for the class of the item selected and then if "text" pass that to the handler and use its reference for your change grep. Also for the change grep preference I prefer using a character style set to no break. That way the modified text does not show up as an override.

set myRegEx to ("(January|February) (\\d{4})")

tell application "Adobe InDesign CC 2018"

  set selList to selection

  set selItem to item 1 of selList

  if class of selItem is text then

set selObj to a reference to selItem

  my doRegEx(selObj, myRegEx)

  end if

end tell

Votes

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
Explorer ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

I've already run into problems using a NoBreak character style because ID doesn't let us stack multiple character styles.

(Example, I can't apply a style called Bold and a style called Italic at the same time. I need to create a 3rd style called Bold Italic. So when I have text that already has a Bold character style applied, then apply a NoBreak character style with a script, it removes the Bold style and I get my knuckles rapped for screwing up the formatting in our documents.)

Votes

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
Explorer ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

LATEST

These solutions are beyond my mental capacity at the moment, but thank you all for responding. At least this thread will be archived in perpetuity in case anyone else is ever looking for this. greenrookie​, Robert Kyle, and S Hopkins​.

Votes

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