Reversing selected text or paragraph

hi all,
i have a document that contains the lines reversed (for example, Hello All is written llA olleH), so how can i reverse a selected line and reverse the text inside the line (assuming i select each line before i run the script), and also how can i reverse the whole document without needing to select every single line at a time?
thanks in advance

Hi,
Hope you are new to scripting, so kindly use the below script.
With the help of vandy coding,
var myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements();
for(i=0; i<myLines.length; i++)
    if(myLines[i].contents.match(/^\r/) !=null)
        continue;
    app.select(myLines[i].characters.itemByRange(0, -2));
    alert("select line")
    myString = app.selection[0].contents; 
    myString = myString.split("").reverse().join(""); 
    app.selection[0].contents = myString; 
Regards
Siraj

Similar Messages

  • How to get paragraph number of selected text in ID CS4

    Hi,
    Can anybody help me how to get paragraph number of selected text in Indesign cs4.
    Thanks,
    Gopal

    Ah, I see -- thanks. Turns out that there's no difference in speed between texts.itemByRange(), characters.itemByRange(),and insertionPoints.itemByRange(). In a document with 170 pages of text, and with the cursor in the last paragraph, the second and third lines, below (and your function), give exactly the same result:
    t = app.selection[0];
    t.parentStory.texts.itemByRange (t.parentStory.insertionPoints[0], t).paragraphs.length;
    t.parentStory.characters.itemByRange (t.parentStory.characters[0], t).paragraphs.length;
    Peter

  • After Updating Adobe Indesign CC ,While I'm selecting text in a paragraph, the text disappears and this problem repeated several times before update everything was ok

    After Updating Adobe Indesign CC ,While I'm selecting text in a paragraph, the text disappears and this problem repeated several times before update everything was ok

    First, see Replace Your Preferences and do it for the original account.
    If that fails to solve the problem, rename the two Adobe folders that contain the prefs in the user profile for that account and copy the folders from the new account where it works. You want to be sure you copy the folders, rather than merge the contents, so you must rename the old folders first.

  • Paragraph Catalog Not Indicative of Selected Text

    I just loaded Framemaker 12 and noticed the the paragraph catalog no longer indicates the tag being used when I select text in teh documents. I cannot find an option to enable this. Any ideas?

    Which point version of FM12? The latest patch brings it up to 12.0.4p445. The catalog highlighting of the tag name at the cursor location was only introduced with the 12.0.3 patch.
    Note: you have to load the patches in order.

  • How do you find and replace "within selected text" in a textedit document (version 1.8, mountain lion)

    In the textedit version on Snow leopard it was possible to search and replace within a peice of selected text only i.e. not the entire file. This was a very useful feature because you could select a paragraph and replace all occurences of word1 with word2 within that paragraph only! This feature appears to be missing from the mountain lion version of textedit (version 1.8). Or can anyone tell me how to do it ... ?

    Having 46 people view a post without replying is not unusual. Some people look at a question to see if it's something they'd like to know the answer to, and then come back  when it has eventually been answered.
    I'm not sure if you need to escape forward slashes in Dreamweaver's Find and Replace dialog box, but I normally do because both JavaScript and PHP normally use forward slashes as delimiters to mark the beginning and end of the regex like this:
    var pattern = /[A-Z]{4}/; // JavaScript
    $pattern = '/[A-Z]{4}/';   // PHP
    When a forward slash appears inside the regex, you need to escape it with a backslash to avoid confusion with the closing delimiter.
    As you have worked out, a capturing group is created by wrapping part of the regex in parentheses.
    If you want to match exactly 38 characters, you can use [\S\s]{38}. That includes spaces, newline characters, symbols, everything.
    If you're trying to find everything between two tags, you can do this:
    (<\/tag_name>)([^<]+)
    The closing tag is captured as $1 and everything up to the next opening tag is captured as $2.
    Learning regular expressions is not easy. I don't claim to be an expert, but I enjoy the challenge of trying to solve them. If you're interested in regular expressions, there are several books published by O'Reilly. "Mastering Regular Expressions" is the ultimate authority, but it's a difficult read (not because it's badly written, but because of the complexity of the subject). "Regular Expressions Cookbook" is very good. There's also a new "Introducing Regular Expressions", but I haven't read it.

  • Problem with selecting text in Adobe Reader XI

    Hi all, I am encountering a problem with Adobe Reader XI and it is very strange I could not find an alike issue on the internet so I guess I have to submit a question with it.
    So here it is, I am using Adobe Reader XI Version 11.0.2, operating system: Windows 7. I do not know it starts from when but it has the problem with selecting text - to be copied in pdf documents. I ensure that the documents are not scanned documents but word-based documents (or whatever you call it, sorry I cannot think of a proper name for it).
    Normally, you will select the text/paragraph you want to copy and the text/paragraph will be highlighted, but the problem in this case that I cannot select the text/paragraph, the blinking pointer (| <-- blinking pointer) will just stays at the same location so I cannot select/highlight anything to be copied. It happens oftenly, not all the time but 90%.
    This is very annoying as my work involves very much with copying text from pdf documents, I have to close the pdf file and then open it again so I can select the text but then after the first copying or second (if I am lucky), the problem happens again. For a few text I have to type it myself, for a paragraph I have to close all opening pdf documents and open again so I could select the paragraph to copy. I ran out of my patience for this, it causes trouble and extra time for me just to copying those texts from pdf documents. Does this problem happen to anyone and do you have a solution for this? I would much appreciate if you could help me out, thank you!

    Yeah,  I totally agree, this is very strange. I have always been using Adobe Reader but this problem only occurred ~three months ago. It must be that some software newly installed I think. But I have no idea.
    About your additional question, after selecting the texts and Ctrl + C, the texts are copied and nothing strange happens. It's just that right after I managed to copy the texts, it takes me a while to be able to select the texts again. For your information, I just tested to select the texts and then pressed Ctrl, the problem happened. And then I tried pressing C and then others letters, it all led to the problem.
    I guess I have to stick with left-clicked + Copy until I/someone figure the source of this problem. Thanks a lot for your help!

  • Selecting Text in Acrobat 9 Pro

    Hello, we have just discovered that
    in some documents that I have converted from Word into a PDF are having problems with selecting text.  When we go to select text,
    rather than just selecting the text I am highlighting, it is only selecting portions as though they are in columns.  I went back to the original Word document and cleared all the formatting (there are no columns in this document...it's just paragraphs), then formated the text size and style and saved it to a PDF, but am still having the same problem.  I have checked older PDF documents which started out the same way in Word, and some have this problem, but some work fine and let me select only a few words or sentences at a time.  But the rest are trying to select words above and below the text I am trying to select.  Any help would be appreciated.

    Hi,
    You might want to look at the "touch up reading order" in advanced, accessibility options. The document will be tagged and you will see the structure of the page. I suspect that it has formatted the text into columns - you can use this tool to clear the page structure and reformat to make the whole page just text reading from left to right.
    BR
    John

  • How to set the desired font to the selected text in textframe?

    Hi,
    I want to change the font(let's say Times New Roman) of selected text in textframe when I click on  menu-item of my plug-in.
    I went through the Adobe Text Engine documentation and  tried some code for setting font but failed. I don't see any member function in IFont class to set desired font, so unable to move forward.
    plz see the code. I would like to know one more thing that how can we set a particular font for a textframe?
    TextRangesRef rangesRef = NULL;
    result = sAIDocument->GetTextSelection(&rangesRef);
    aisdk::check_ai_error(result);
    ITextRanges ranges(rangesRef);
    if (ranges.GetSize() > 0)
         ITextRange range = ranges.Item(0);
         ICharFeatures features = range.GetUniqueLocalCharFeatures();
         IFont  font;                     // I don't see any method to put desired font.
       // features.SetFont(); 
    Thanks.
    D.A

    First, get the font:
    AIFontKey fontKey = 0;
    AIErr error = sAIFont->FindFont("Times New Roman Regular", kAIAnyFontTechnology, kNativeAIScript, 0, &fontKey);
    // do something with error
    ATE::FontRef fontRef = 0;
    error = sAIFont->FontFromFontKey(fontKey, &fontRef);
    // do something with error
    ATE::IFont font(fontRef);
    Then, apply it like this:
    ATE::TextRangeRef textRangeRef = 0;
    AIErr error = sAITextFrame->GetATETextRange(handle_to_artwork, &textRangeRef);
    // check error
    ATE::ITextRange textRange(textRangeRef);
    ATE::ICharFeatures charFeatures = textRange.GetUniqueLocalCharFeatures();
    charFeatures.SetFont(font);
    textRange.ReplaceOrAddLocalCharFeatures(charFeatures);
    There are a few other ways to set the text, but you need to understand how character & paragraph styles interact with each other to understand the differneces. This is the most straight forward way to do it though.

  • [JS, CS3] Need help changing tabStop positions of selected text

    Hi all,
    I am writing a script to nudge the tabStop positions of selected text by one point at a time. Sometimes it will be only a tab character selected, and other times it could be several in the paragraph or maybe even the whole story. The problem I am encountering is that when I reference the tabStops as app.selection[0].tabStops it includes ALL the tabStops in the paragraph and NOT just the selected ones. Is there a way to get just the selected tabStops and add a point to their positions? It must be that my referencing is flawed. Thanks for any help.
    Regards,
    Len Swierski

    Hi Len,
    That's not a bad approach, but remember that there may be more tab characters than there are tab stops. I was thinking of getting the location of the selected tab stop relative to the left edge of the text frame (or column, if you're working with multi-column frames) and then comparing it to the location of the tab stop. But I think your approach will work just as well and be quicker.
    Also, remember that when you start moving tab stops around, the index of the tab stop within the tab stops collection can change. If you have tab stop A at 12pt and tab stop B at 16pt, then tab stop A will be item(0) and B will be item (1). But if you move A to 24pt, A will become item(1) and B will be item(0). The index of the tab stop is relative to its location on the tab ruler.
    Thanks,
    Ole

  • How to determine the size of selected text

    Hi
    I'd like to draw a box around some selected text (a textRange), however I can't figure out how to detemine the size or position of the text.  The overall size of a textFrame is possible to find (not sure about position), but when you've got just a few characters selected I don't see any way to get the size or position.  Any ideas?

    You may have to do some testing of your own with this… I tested here and 'think' its OK but could have overlooked something… For me the best way to get this data is to outline the type store the info in a variable then undo the outlining process… You can then continue your script with info in hand… An example that draws a box over each selected character… I cheated with only the one text frame but you can resolve that? You could easy use math.min & math.max to draw around an array of bounds… I didn't bother with a load of tests it expects selected text range as is… have fun…
    #target Illustrator
    textBoxer();
    function textBoxer() {
              var i, doc, sel, start, end, spaceB4, spaceInc, mat, grp, count, boxes;
              doc = app.activeDocument;
              sel = doc.selection;
              start = sel.characterOffset-1; // Not zero based…
              end = start + sel.length;
              doc.selection = null;
              spaceB4 = doc.textFrames[0].contents.substr( 0, start );  // Cheated here you will need to find parent frame…
              mat = spaceB4.match( /\s/g ); // Resolve the lost of white space characters before selection
              mat != null ? spaceB4 = mat.length : spaceB4 = 0;
              spaceInc = doc.textFrames[0].contents.substr( 0, end );  // Here too…
              mat = spaceInc.match( /\s/g ); // Resolve the lost of white space characters in selection
              mat != null ? spaceInc = mat.length : spaceInc = 0;
              grp = doc.textFrames[0].createOutline(); // Items in new group are last to first order
              app.redraw();
              count = grp.compoundPathItems.length;
              boxes = Array();
              for ( i = 0; i < count; i++ ) {
                        boxes.push( grp.compoundPathItems[i].visibleBounds );
              boxes.reverse(); // Fix the order
              app.undo(); // Bounce back…
              app.redraw();
              start = start - spaceB4;
              end = end - spaceInc;
              for ( i = start; i < end; i++ ) {
                                  doc.pathItems.rectangle( boxes[i][1], boxes[i][0], boxes[i][2]-boxes[i][0], -boxes[i][3]- -boxes[i][1], false );
              app.redraw();

  • Scrolling selected text with Indesign CS6 to show different font style

    Hi, I recently found I could highlight a paragraph and using font character style I could scroll through fonts changing whole paragraphs, I can't remember how I did this, I know it's a new feature with CC, I'm on CS6

    Select the text you want to change. Click your cursor after the font name in the field. Press the up or down arrows, and you can see the selected text change.

  • Pages '09: Can't use AppleScript for selected text inside tables?

    When I run get selection on selected text in a Pages document, I get something like this:
    <pre>text from character 1 to character 4 of body text of document id 9943974 of application "Pages"</pre>
    When I run get selection on selected text inside a table cell in a table in a Pages document, I get something like this:
    <pre>text from character 1 to character 4 of some table of document id 3539679 of application "Pages"</pre>
    When I run get selection on selected text inside a table cell in ANOTHER table in the same Pages document, I get the exact same thing. It still says "some" table. So there is no way to distinguish between tables if there are more than one table in the same Pages document.
    Am I correct in understanding that this means that most AppleScript commands for manipulating text are unusable inside table cells?
    For example, it seems impossible to get the properties of the selection when the selection is selected text inside "some" table. So it's impossible do anything about text styles, etc.
    Is AppleScript support in Pages ’09 really that limited, or am I missing something?

    The first script below should return the character style of any selection made in Pages ’09, whereas the second script should apply the "XXX" character style to any selection:
    --BEGINNING OF SCRIPT 1
    tell application "Pages"
    activate
    tell application "System Events" to tell process "Pages"
    -- Show the format bar:
    if not (pop up button 1 of window 1 exists) then
    click menu item "Show Format Bar" of menu 1 of menu bar item "View" of menu bar 1
    end if
    -- Show the styles drawer and character styles:
    if menu item "Show Styles Drawer" of menu 1 of menu bar item "View" of menu bar 1 exists then
    keystroke "t" using {shift down, command down}
    end if
    tell front window
    tell checkbox 1 of group 1 of drawer 1 -- “Show or hide character styles.” checkbox
    repeat until it exists
    delay 0.1 -- wait until the styles drawer is open
    end repeat
    if description is "show character style" then click
    end tell
    -- Get the row index (although it is not a property) of the character style:
    tell menu button 2 -- “Choose a character style.” menu button
    click
    set k to 0
    repeat
    set k to k + 1
    if value of attribute "AXMenuItemMarkChar" of menu item k of menu 1 exists then exit repeat
    end repeat
    keystroke return -- hide the menu
    end tell
    -- Get the character style name:
    if k > 1 then set k to k + 1
    value of static text 1 of row k of outline 1 of scroll area 2 of splitter group 1 of group 1 of drawer 1
    end tell
    end tell
    end tell
    --END OF SCRIPT 1
    --BEGINNING OF SCRIPT 2
    set myStyle to "XXX" -- the name of the character style you want to apply
    tell application "Pages"
    activate
    tell application "System Events" to tell process "Pages"
    -- Show the format bar:
    if not (pop up button 1 of window 1 exists) then
    click menu item "Show Format Bar" of menu 1 of menu bar item "View" of menu bar 1
    end if
    -- Show the styles drawer and character styles:
    if menu item "Show Styles Drawer" of menu 1 of menu bar item "View" of menu bar 1 exists then
    keystroke "t" using {shift down, command down}
    end if
    tell front window
    tell checkbox 1 of group 1 of drawer 1 -- “Show or hide character styles.” checkbox
    repeat until it exists
    delay 0.1 -- wait until the styles drawer is open
    end repeat
    if description is "show character style" then click
    end tell
    set characterStyles to value of static text 1 of rows of outline 1 of scroll area 2 of splitter group 1 of group 1 of drawer 1
    set k to 0
    repeat with thisStyle in the characterStyles
    set k to k + 1
    if thisStyle as text is myStyle then exit repeat
    end repeat
    -- Apply the character style:
    if k > 1 then set k to k - 1
    click menu button 2 -- “Choose a character style.” menu button
    click menu item k of menu 1 of menu button 2
    end tell
    end tell
    end tell
    --END OF SCRIPT 2
    I suppose that +paragraph styles+ should work the same.
    I'm beginning to know Pages ’09 a little better now.
    Message was edited by: Pierre L. (show format bar)

  • [CS3][JS] Apply XML tag for selected text

    Hi
      I need to apply XML tag to selected text in a tagged content.The XML tag is already applied for paragraph.I need to apply XML Tag for selected text in a paragraph.
    I have used following code, it applies tag for entire paragraph,not a selected text in a paragraph.
    app.selection[0].associatedXMLElements[0].markupTag=myDoc.xmlTags.item("italic");
    Please suggest me.
    Regards
    kumar

    The example script, markup.jsx
    //Markup.jsx
    //An InDesign CS4 JavaScript
    //Shows how to use the markup method.
    main();
    function main(){
        mySetup();
        mySnippet();
        myTeardown();
    function mySetup(){
        var myDocument = app.documents.add();
        var myPage = app.activeWindow.activePage;
        var myRootXMLElement = myDocument.xmlElements.item(0);
        var myXMLTag = myDocument.xmlTags.add("xml_element");
        var myXMLElementA = myRootXMLElement.xmlElements.add(myXMLTag);
        myXMLElementA.contents = "This is a paragraph in an XML story.";
        var myTextFrame = myPage.textFrames.add({geometricBounds:myGetBounds(myDocument, myPage)});
        myTextFrame.contents = "This is the first paragraph in a text frame.\rThis is the second paragraph in a text frame.\rThis is the third paragraph in a text frame.\rThis is the fourth paragraph in a text frame.\r";
    function mySnippet(){
        //<fragment>
        var myDocument = app.documents.item(0);
        var myPage = myDocument.pages.item(0);
        myDocument.xmlElements.item(0).xmlElements.item(0).markup(myPage.textFrames.item(0));
        //</fragment>
    function myTeardown(){
    function myGetBounds(myDocument, myPage){
        var myPageWidth = myDocument.documentPreferences.pageWidth;
        var myPageHeight = myDocument.documentPreferences.pageHeight
        if(myPage.side == PageSideOptions.leftHand){
            var myX2 = myPage.marginPreferences.left;
            var myX1 = myPage.marginPreferences.right;
        else{
            var myX1 = myPage.marginPreferences.left;
            var myX2 = myPage.marginPreferences.right;
        var myY1 = myPage.marginPreferences.top;
        var myX2 = myPageWidth - myX2;
        var myY2 = myPageHeight - myPage.marginPreferences.bottom;
        return [myY1, myX1, myY2, myX2];
    I think you can use the markup function on the selected item (Text Object have a markup method)
    Thomas B. Nielsen
    http://www.lund-co.dk

  • Script to add markers to text by paragraph format

    With previous versions of Framemaker, I had a FrameScript which would loop through my document and add a marker to text based on the paragraph format applied. The marker text would be the selected paragraph.
     I am now trying to recreate this in Extendscript for use in Framemaker 10 and am completely stumped. 
    I have no doubt that my script (copied below) is completely off-track, but I wondered if anybody would be able to help point me in the direction of my many mistakes.
    Basically, I want the script to find all paragraphs with the "*Part no." format applied, make that text the text range and then apply a marker to that range. A bit of research has shown that I probably need to create a list of paragraph formats, but I believe that I have far more problems than just that.
    var pgfFmt1 = flow.GetNamedPgfFmt (*Part no.);
    while (pgfFmt1.ObjectValid())  
        function createMarker (doc, pgf, offset, type, text)    {
            var tRange, marker;
            tRange = pgfFmt1.TextRange;
            marker = doc.NewAnchoredObject(Constants.FO_Marker, tRange);
            marker.MarkerType = type;
            marker.MarkerText = text;
            return 1;
    createMarker (doc, pgf, 0, "Index", 0);
    Many thanks in advance to anyone who is able to offer me some pointers!

    Well, it seems that my script is only 95% there. While my script finds the target paragraphs and adds a marker, only the first word of each paragraph is selected as the marker text. I really need the script to select the whole paragraph as the marker text. I have tried many combinations, but cannot seem to get the right outcome. Could anybody please point me in the right direction? Script is copied below. Many thanks!
    var doc = app.ActiveDoc;
    var flow = doc.MainFlowInDoc;
    var tframe = flow.FirstTextFrameInFlow;
    var pgf = tframe.FirstPgf;
    var target1 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Part no.");
    var target2 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Parent Bold");
    var target3 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Child");
    var target4 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Child indent");
    var target5 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Child indent 2");
    while (pgf.ObjectValid())   {
    if (pgf.Name == target1.Name)   {
        createMarker (doc, pgf, 0, "Index", "");
    else if (pgf.Name == target2.Name)  {
        createMarker (doc, pgf, 0, "Subject", "");
    else if (pgf.Name == target3.Name)  {
        createMarker (doc, pgf, 0, "Subject", "");
    else if (pgf.Name == target4.Name)  {
        createMarker (doc, pgf, 0, "Subject", "");
    else if (pgf.Name == target5.Name)  {
        createMarker (doc, pgf, 0, "Subject", "");
    pgf = pgf.NextPgfInDoc;
    function createMarker(doc, pgf, offset, type, text) {
        var tLoc = new TextLoc(pgf, offset);
        var marker = doc.NewAnchoredObject(Constants.FO_Marker, tLoc);
        var markerType = doc.GetNamedObject(Constants.FO_MarkerType, type);
        marker.MarkerTypeId = markerType;
        marker.MarkerText = text;
        return 1;

  • Script to apply a style to currently selected text

    I can only find example scripts that work on complete files. What I want, is a script that works on currently selected text.
    If I can create a macro that applies a specific paragraph style to all currently selected paragraphs, or a character style to currently selected text, I can put that style under a shortcut key.
    That way, "emphasis" or "strong" can be put under ctrl-b, for example.
    If there is another way to achieve the same (in RH 9), I would be interested to hear it as well.
    Kind regards,
    Erwin Timmerman

    I had a quick look at Macro Express, but it seems that it only records key strokes and mouse clicks etc. This means that it only works if I have the style pod constantly open (which I do), always in the exact same position, with the same filter styles selected, and with the same CSS loaded, positioned at the same location in the scroll bar.
    Am I correct in assuming this, or is there a better way to program it?
    I am not sure this would be possible all the time. What's more, this script should work across multiple computers with different layouts, and with writers who don't really want to hack to get it working.
    With character styles there would be the possibility to automatically switch to HTML view, cut, write <span...>, paste, write </span>, go back to design view.
    But paragraph styles? That would be harder to do in HTML view, especially for multiple selected lines.

Maybe you are looking for

  • How to start a Jar file in another directory?

    Hello! I have 2 questions, hope someone can help me... 1) I have a GUI which is placed in C:/java/tmp/GUI.java. When I run this program I want it to start runing a JAR file which is placed in d:/tmpdir/app.jar. How do I do this? 2) How can I get the

  • Ipad mini activation error

    Hey, i m using an ipad mini. It was workinng all fine till yesterday. Today when I got up its showing up a screen "Activation Error: device is not registered as part of something". How can I fix it??

  • Using Paypal with Itunes Store

    Ok, I have a paypal account. However, I just use it with my bank account and do not have a credit card on file. What I want to do is register my paypal account with my itunes account and use my paypal balance to purchase songs. However, everytime I c

  • Cursor going haywire!

    My keyboard is POSSESSED! Problem started this a.m. that I'll be typing and suddenly realize that my insertion point has jumped around. Happens at random in all software (mail, address book safari). Software up to date. Re-booted, no help.

  • Assembly processing  profit center

    Dear all, i trigger the project by saving the sales order. there is a problem. when i check the project using CJ20N, i found that the profit center is DUMMY in the basic data. the profit center should be automatically genenrated in line with the mate