0

So what I'm doing right now is surfing the text to find the following mark for footnotes: .15 and I'd like to change it to 15. where 15 becomes superscript. Is there a way to do this using a keybind and possibly GREP? I can apply a new paragraph style that involves grep, just not sure how to make it swap the locations. Also, I can't auto-search this, because there's other instances where .15 shouldn't be swapped. So I just wanna select the format .number and have that selection swap to number. and change number to superscript.

Predrag Beocanin
  • 1,402
  • 3
  • 18
  • 25

2 Answers2

2

Slighty modified:

#target indesign
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(\\.)(\\d+)";
app.changeGrepPreferences.changeTo = "$2$1";
var 
    mTarget = app.activeDocument,
    mFound = mTarget.findGrep(),
    cText;
//
while (cText = mFound.pop())
    if (checkCondition(cText)) 
        doJob(cText);

alert ("No more found. Done.");
app.findGrepPreferences = app.changeGrepPreferences = null;
//
function checkCondition (testText) {
    if (testText.appliedParagraphStyle.name == "pstyle")
    return true;
    else return false;
    }
function doJob (testText) {
    testText.showText();
    if (!confirm("Replace?")) return;
    testText.changeGrep();
    testText.characters.itemByRange(0,-2).position = Position.SUPERSCRIPT;
    }

It is asking before change ("No" means go to next).

Watch condition set ==> applied paraStyle.name == "pstyle"

Jongware
  • 22,200
  • 8
  • 54
  • 100
Cashmirek
  • 269
  • 1
  • 9
0

Suggest to run a script but there are 2 questions: 1. what is a target (doc? selected text?) 2. how to filter proper instances of "dotDigits" (specific paragraf style only?)

Code could be like this:

#target indesign
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(\\.)(\\d+)";
app.changeGrepPreferences.changeTo = "$2$1";
var 
    mTarget = app.activeDocument,
    mFound = mTarget.findGrep(),
    cText;
// iterate through found texts
while (cText = mFound.pop())
    if (checkCondition(cText)) doJob(cText);
//
app.findGrepPreferences = app.changeGrepPreferences = null;
//
function checkCondition (testText) {
    var mRes = true;
    // how to filter proper instances of found text?
    return mRes;
    }
function doJob (testText) {
    testText.changeGrep();
    testText.characters.itemByRange(0,-2).position = Position.SUPERSCRIPT;
    }

Warning: For now - a target for above code is every instance found in entire doc

Jarek

Cashmirek
  • 269
  • 1
  • 9
  • Hey jarek, thanks for the reply. Basically, when I find "dotDigit" and double click it, it will always select both, so target would be selection. The "dotDigit" formation is always found in the style that we can call "pstyle". I would prefer if I could trigger this script with a hotkey on the selection alone? Safer that way. Cheers! – Predrag Beocanin Nov 09 '16 at 21:22