How can I search and replace the order items appear in the document?

Here is my script. I am trying to replace instances of a text pattern (Lot ^9^9^9^9^9) with an auto incremented number Lot 1, Lot 2, Lot 3, etc... I believe this script produces unexpected results becuase the search result is ordered by document construction. The first item in myfounditems is the last item added to the document (which is on the last pages of the document), the second item in myfounditems is the next to last item that was added to the document (which was moved to a middle page in the document). The net result is that instead of having the first item on the first page being Lot 1) and the item directly below it being Lot 2), my document is a hodgepodge of Lot numbers is a seeminlgly random order. Any thoughts on how to fix this?
tell application "Adobe InDesign CS5.5"
  --Clear the find/change preferences.
          set find text preferences to nothing
          set change text preferences to nothing
  --Search the document for the string "lot".
          set find what of find text preferences to "Lot ^9^9^9^9^9)"
  #set change to of change text preferences to "Lot " & lotnum & ")"
  --Set the find options.
          set case sensitive of find change text options to false
          set include footnotes of find change text options to false
          set include hidden layers of find change text options to false
          set include locked layers for find of find change text options to false
          set include locked stories for find of find change text options to false
          set include master pages of find change text options to false
          set whole word of find change text options to false
          tell active document
                    set lotnum to 1
                    set myFoundItems to find text
                    repeat with foundItem in myFoundItems
                              set contents of object reference of foundItem to "Lot " & lotnum & ")"
                              set lotnum to lotnum + 1
                    end repeat
          end tell
end tell
display dialog ("Numbered " & (count myFoundItems) & " lots in this document. Next starting lot number is " & lotnum & ".")

You noticed the first one yourself: the Found item list seems to randomly jump around the document -- I believe you are correct in your observation it may be due to the object construction order. That tells me, by the way, something about your lot numbers that tou didn't mention: your text is not one continuous long threaded story, but it's all or partially in disconnected etxt frames. The Found list does return everything inside a single story in the correct order, but it goes over each separate story in the order they were constructed.
The only solution is to gather all of your lot numbers, *re-sort* them according to the page number they appear on (and some sort of Worst Case Scenario is when you might have more than one lot number frame per page; in that case you also need to sort by textframe, top to bottom -- yet even worse is if you also may have these textframes side by side!).
Only then you have a reliable counting order.
This isn't too bad. We can just extend the method I offered for sorting top-to-bottom/left-to-right in Re: Working around the frame selection order issue in CS 4 and make it also include page numbers:
function byPageYX(a,b) {
    var
        aP = a.parentTextFrames[0].parentPage.index,
        bP = b.parentTextFrames[0].parentPage.index,
        aY = a.baseline[0],
        bY = b.baseline[0],
        aX = a.horizontalOffset[1],
        bX = b.horizontalOffset[1],
        dP = aP-bP,
        dy = aY-bY,
        dx = aX-bX;
    return dP?dP:(dy?dy:dx);
myResults.sort(byPageYX);
Or something like that.
As for actually implementing the above I cannot be of any help with Applescript.
Once we're dealing with sorting I think you're much better off in Javascript anyhow.

Similar Messages

  • How can I search and replace fonts?

    iOS 7 doesn't support the Adobe workhorse fonts I've most relied on for years, and arbitrarily changes them to iOS built-in fonts when I link my standard documents and templates to the iPhone, via iCloud. There's no apparent logic to how it does this; a Pages document in Minion Pro, a serif font, gets changed to the sans-serif Helvetica. Myriad Pro may come out in Times New Roman. I accept that the iPhone's limited number of fonts makes translation necessary, but does Pages offer a way in which I can search and replace inappropriately substituted fonts for more logical alternatives?

    You noticed the first one yourself: the Found item list seems to randomly jump around the document -- I believe you are correct in your observation it may be due to the object construction order. That tells me, by the way, something about your lot numbers that tou didn't mention: your text is not one continuous long threaded story, but it's all or partially in disconnected etxt frames. The Found list does return everything inside a single story in the correct order, but it goes over each separate story in the order they were constructed.
    The only solution is to gather all of your lot numbers, *re-sort* them according to the page number they appear on (and some sort of Worst Case Scenario is when you might have more than one lot number frame per page; in that case you also need to sort by textframe, top to bottom -- yet even worse is if you also may have these textframes side by side!).
    Only then you have a reliable counting order.
    This isn't too bad. We can just extend the method I offered for sorting top-to-bottom/left-to-right in Re: Working around the frame selection order issue in CS 4 and make it also include page numbers:
    function byPageYX(a,b) {
        var
            aP = a.parentTextFrames[0].parentPage.index,
            bP = b.parentTextFrames[0].parentPage.index,
            aY = a.baseline[0],
            bY = b.baseline[0],
            aX = a.horizontalOffset[1],
            bX = b.horizontalOffset[1],
            dP = aP-bP,
            dy = aY-bY,
            dx = aX-bX;
        return dP?dP:(dy?dy:dx);
    myResults.sort(byPageYX);
    Or something like that.
    As for actually implementing the above I cannot be of any help with Applescript.
    Once we're dealing with sorting I think you're much better off in Javascript anyhow.

  • I have just put an audio book into my iTunes music library.  When I tried to transfer it to my iPod shuffle it rearranged the tracks so that they are in the wrong order.  How can I put them in the order they appear in the book?

    I have just put an audio book into my iTunes music library.  When I tried to transfer it to my iPod Shuffle it put the chapters in the wrong order i.e. Chap 1, Chap 10, Chap 11 etc. rather than Chap 1, Chap 2, Chap 3 ...  How can I get it to put them in the order they appear in the book?

    First, we need to know if the audiobook chapters are being treated by iTunes as music files or as audiobooks. If they are not audiobooks purchased from the iTunes store, they might be getting "shuffled". You will need to look at "File" - "Properties" (I think - I don't use iTunes under Windows - or right-click on the file and choose "properties") and look at the media type. If it is "Music", change it to "Audiobook". If this is not the problem, or does not fix anything, please post back.
    Actually, looking at your post again, a second thought occurs to me - assuming there are less than 100 chapters in the book, just renaming them with a leading zero on the first nine chapters might do it. A computer will alphabetically sort filenames in the order you quote (1, 10, 11, 12, 13, ... 2, 21, etc.) but a leading zero will fix that (01, 02, 03 ... 10, 11, 12)

  • How can I remove and replace a purchased app that is malfunctioning.

    How can I remove and replace a purchased app that is malfunctioning.?

    Delete the App and redownload it...
    Touch the app and hold your finger down until all the apps start to jiggle.
    You will see a circled "x" in the upper left corner.
    Tap it to delete an app. When done press the Home button.
    ( You cannot delete any pre-installed iOS app.)
    http://www.apple.com/support/ipad/applications/
    Download Past Purchases
    http://support.apple.com/kb/HT2519
    Log into iTunes using the account the Purchase was made with... Click on Buy... and a notice will come up saying you already have it... do you wish to download it again... Click Yes...

  • HT201365 how can i search my iphone if i'm not activate the button find my iphone?

    how can i search my iphone if i'm not activate the button find my iphone? is it my handphone can still be found?

    No sorry, other than physically looking for it.
    Call your carrier and report to the police.
    Change all passwords used in iPhone.
    Lost or Stolen
    http://support.apple.com/kb/HT2526
    Message was edited by: ckuan

  • How can I cut and paste from a webpage to a Word document without the document taking me to the web address when I click on a word in the document?

    How can I cut and paste from a webpage to a Word document without the document taking me to the web address when I click on a word in the document?

    You are trying to copy a link, it is most likely in a different color such as the words "Microsoft's own forums" in his post. In Word highlight the word or words, control click on them, select Hyperlink, then Edit Hyperlink, then delete the link from the top box. It will then have a button asking if you want to "Remove Link", click on it.

  • How can I get a downloaded ringtone/song to appear in the settings/sounds/Ringtones menu area on Iphone 4?

    How can I get a downloaded ringtone/song to appear in the settings/sounds/Ringtones menu area on Iphone 4? Thanks

    You must create the ringtones.  google will find several free ways to do this.
    It will then appear in the "Ringtones" section of your itunes "Library".
    Then you select it to sync under the ringtones tab.

  • Can i search and replace in the itunes library database file?

    Hi --
    I need to update the file location in the itunes database for a few thousand songs. These songs are just part of my full collection. A few hundred of these songs are referenced in playlists. Rebuilding the libarary, consolidating the library, adding the new folder to library -- none of these suggested solutions to similar problems will work for me. (My collection is too large for one drive and is spread over several drives, and I have many playlists with hundreds of songs, and the playlists would be ruined with any of these approaches.)
    I thought I had an easy solution by doing a search and replace in "itunes library.xml," replacing the old file path with the new one. But then I learned (as you probably already know) that the real information is stored in "itunes library," and the xml file is just a downstream copy of that information. All my edits were overwritten as soon as I opened itunes.
    The solution to my problem is completely straight-forward if I can just do a search and replace in "itunes libray." Is it possible to edit that file directly? The only database program I have is MS Access, on windows, and it couldn't open the file.
    Thanks very much
    - Mark

    How to Move Your Music to a New Computer.

  • How do I search and replace for invisibles in Pages 5.5.2?

    Three related problems all involving search and replace for invisibles.
    1. A block of text where all double returns need to become single returns.
    2. A block of text where all returns need to be replaced with a single word space.
    3. A block of text where all double word spaces to be replaced with a single word space.
    Pages 09 could do all three this handily. How can these be done in Pages 5.5.2?
    Appreciated.

    Here are screenshot of my attempts to make reducing double returns to one. First up selection of a double return:
    Copy to the clipboard. Do a Command-F. Here's the resulting dialogue:
    I paste in the contents of the clipboard:
    Note the Search field no longer has an empty slot selected. Something is clearly in there, but no instance of whatever is has been found. Nevertheless, I proceed to set up the Replace field by selecting a single return:
    Copy that to the clipboard and paste into the Replace field:
    Nothing to search for and therefore nothing to replace. Am now wondering what that little scoop to the right of the eyeglass icon might indicate. Clicking on it reveals this:
    Definitely not "a solution that just works."

  • How do I search and replace in comments in Acrobat XI?

    I use a Mac and just downloaded Acrobat Pro XI specifically to search and replace phrases in comments in a large PDF. According to this Adobe Help page, I should be able to do this: https://helpx.adobe.com/acrobat/using/searching-pdfs.html I copied the relevant section below and marked with ***. However, I don't see I don't see an arrow for the options that would allow me to include comments. I understand how to include the comments with advanced search, but I want to also replace text. I also checked in preferences and searched the forums. Could someone please advise and maybe include a screenshot, if possible. Thanks!
    Choose Edit > Find (Ctrl/Command+F). 
    Type the text you want to search for in the text box on the Find toolbar. 
    To replace text, click Replace With to expand the toolbar, then type the replacement text in theReplace With text box. 
    (Optional) Click ***the arrow ***next to the text box and choose one or more of the following: 
    Whole Words Only 
    Finds only occurrences of the complete word you type in the text box. For example, if you search for the word stick, the words tick and sticky aren’t found.
    Case-Sensitive
    Finds only occurrences of the words that match the capitalization you type. For example, if you search for the word Web, the words web and WEB aren’t found.
    Include Bookmarks
    Also searches the text in the Bookmarks panel.
    ***Include Comments***
    Also searches the text of any comments.

    Here are screenshot of my attempts to make reducing double returns to one. First up selection of a double return:
    Copy to the clipboard. Do a Command-F. Here's the resulting dialogue:
    I paste in the contents of the clipboard:
    Note the Search field no longer has an empty slot selected. Something is clearly in there, but no instance of whatever is has been found. Nevertheless, I proceed to set up the Replace field by selecting a single return:
    Copy that to the clipboard and paste into the Replace field:
    Nothing to search for and therefore nothing to replace. Am now wondering what that little scoop to the right of the eyeglass icon might indicate. Clicking on it reveals this:
    Definitely not "a solution that just works."

  • How Do I Mass Search and Replace Swatch Colors In Entire Indesign CS6 Document?

    I've jumped from CS4 to CS6 and its been a little while since, but just trying to refamiliarize myself with the many Features of Indesign CS6.
    Here's my issue: I have a really old CS4 document I've opened up and saved in CS6. I have to change all swatch colors throughout the document from pantone swatch 295 C to updated pantone swatch 293 C.
    Question, without my having to go through the entire document one object at a time looking for each object, HOW do i perform a Mass search and replace of Color swatch references from 295 C to 293C.
    I thought i could just click swatch properties and update the color... but No... that doesnt work as swatch properties is just grayed out
    I'm sure i've overlooked something but a refresher on how to mass find and replace color in a document would be great.
    Thanks and looking forward to hearing from someone.

    Thanks for the tips.... both seem like good options without my having to purchase a 3rd party software to accomplish this...
    I must admit... Because I've been stuck in Web Design and Motion Graphics for the past couple of years, when I re-opened my old print work from the CS4 days into CS6 it is obvious I have some catch up to do....
    I was almost embarrassed to admit I had forgotten the technique of Alias one color to another using Ink Manager... I had to look it up and found this helpful tutorial http://indesignsecrets.com/alias-one-color-swatch-to-another.php
    Thanks for both solutions....

  • 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.

  • How can I move most used mail accounts to appear at the top of the list when I open my mail app?

    I have updated iPhone4 to IOS7 and now my mail accounts are in new order.   I have several accounts but a few that need to be the most visible.  Not sure how iPhone mail app is sorting them but it sorting it but definitely not alphabetically or by most used.  Anyway, I finally figured out how to reorder them to suit me and, since help wasn't found on forum, thought I'd share:
    Open Mail App, then use "Edit" from top right.  You'll see a 3-bar icon to the right of each mail account.  Use it to slide accounts up/down to where you want them.  Works also for any Gmail accounts you might have.
    Sometimes it's the simple things

    cor-el, thanks for the tip. While I certainly scoured Adobe's preference settings to look for something relating to that exact thing, I never went to their help site until I got your post. I found out that the floating toolbar appears because the PDF opens in'' Read Mode'', which you can turn off for all future documents by doing this:
    * Quit your internet browser
    * Launch Acrobat (or Reader)
    * Choose Edit>Preferences
    * Click on the Internet category on the left
    * Deselect “Display in Read Mode by default”
    * Click the OK button.
    * Relaunch Acrobat
    Something important to note, if you have both Adobe Acrobat and Adobe Reader, you need to do the above in both programs (same steps).

  • How can i search and retrieve the first word ...

    How can i retrieve the FIRST or the SECOND word in a document stored in a file_datastore ?
    Thanks
    null

    You noticed the first one yourself: the Found item list seems to randomly jump around the document -- I believe you are correct in your observation it may be due to the object construction order. That tells me, by the way, something about your lot numbers that tou didn't mention: your text is not one continuous long threaded story, but it's all or partially in disconnected etxt frames. The Found list does return everything inside a single story in the correct order, but it goes over each separate story in the order they were constructed.
    The only solution is to gather all of your lot numbers, *re-sort* them according to the page number they appear on (and some sort of Worst Case Scenario is when you might have more than one lot number frame per page; in that case you also need to sort by textframe, top to bottom -- yet even worse is if you also may have these textframes side by side!).
    Only then you have a reliable counting order.
    This isn't too bad. We can just extend the method I offered for sorting top-to-bottom/left-to-right in Re: Working around the frame selection order issue in CS 4 and make it also include page numbers:
    function byPageYX(a,b) {
        var
            aP = a.parentTextFrames[0].parentPage.index,
            bP = b.parentTextFrames[0].parentPage.index,
            aY = a.baseline[0],
            bY = b.baseline[0],
            aX = a.horizontalOffset[1],
            bX = b.horizontalOffset[1],
            dP = aP-bP,
            dy = aY-bY,
            dx = aX-bX;
        return dP?dP:(dy?dy:dx);
    myResults.sort(byPageYX);
    Or something like that.
    As for actually implementing the above I cannot be of any help with Applescript.
    Once we're dealing with sorting I think you're much better off in Javascript anyhow.

  • How can i find and replace xml tags?

    Hi, i am using xml in my workflow and want to be able to remove certain tags if they contain particular text.
    here is an example of my xml structure…
    <entry>
        <name>DEFAULT</name>
        <tel>DEFAULT</tel>
        <address>DEFAULT</address>
    </entry>
    I am using this initial structure to set the paragraph styles to be followed when the xml data is imported.
    This leaves DEFAULT in place wherever an entry doesn't have any content for that field.
    I want to be able to import my XML then run a script that removes any tags that include DEFAULT, - I need the entire xml tag to be removed not just the text, if i do a normal find and replace it will only remove the text not the tags which is causing problems with styling. I also want to remove the end of para/return (^p) that i've placed at the end of the line. So it would be the same as opening up story editor and removing the content + tags + hard return in there, but i want to automate the process…
    So i think this is what i need to search for in each case
    "<name>DEFAULT</name>^p"
    and i want to replace it with nothing ""
    Can this be done through scripting (ideally javascript)?
    I have a little knowledge of javascript but am not sure how to search and target that kind of string in indesign...
    using indesign cs5
    many thanks

    Hi,
    Script should do it in two steps:
    1. find all occurences of i.e. ">DEFAULT<"
    2. remove whole paragraph which is a found_text's container.
    For example this way -JS - (a textFrame filled with your text should be selected) :
    var mStory = app.selection[0].parentStory;
    app.findTextPreferences =  null;
    app.findTextPreferences.findWhat = ">DEFAULT<";
    var myF = mStory.findText();
    var count = myF.length;
    while (count--)
         myF[count].paragraphs[0].remove();
    rgds

Maybe you are looking for

  • Import VHS- C??

    I'm sorry for my ignorance here. I have a VHS-C camcorder that is a few years old. I have a bunch of tapes (VHS and VHS-C) that I want to save on DVD. Is there a good way to import these to my iBook and then burn them to DVD or should I just buy a st

  • Site not accessable in VRF

    Hi, I have a L3 VPN customer, in my MPLS network who works in a MESH topolgy.Customer is connected to PE on a E1 link. I am finding a problem with one location of the customer. Below is the problem statement and work around done. 1. Customer is not a

  • GetURL or javascript resolution? to controlling PDF browser

    Okay.. so here is the scenario. I am creating a CD that has a Flash projector. The Flash projector links to PDF files located on the same CD. Everything works great.. except that when you click on the link to open up the PDFs, they open in separate w

  • How many computers can I put CS5 Production Premium on?

    How many computer can I put CS5 Production Premium on if I were to buy it for my company?

  • [SOLVED] Trackpoint on Thinkpad T61p stopped working

    After todays updates (I think kernel might be the one) my trackpoint stopped working completly. Also I get no output on /dev/input/mouse0, which I think was the place I was linked to.. Last edited by miro279 (2012-04-17 20:10:52)