in

Quark Forums

Hi how to use find and replace

Last post 06-27-2008 7:05 AM by Scripting_Ace. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 06-26-2008 5:57 AM

    Hi how to use find and replace

    Hi,

    Im new to quarkXPress and applescript. I want to search for a content in quark document and replace it with null values.

    I tried using many seacrh and replace function but it is not working.The code i used is

    tell application "QuarkXPress"
        activate
        tell document 1
            set TheStories to count of every story
            repeat with i from 1 to TheStories
                set mysearch to (a reference to (text of story i whose contents of it = "means writing"))
                set contents of mysearch to "Figure"
                return
            end repeat
        end tell
    end tell

    Input:Communication means writing, speaking, and showing visuals to other people, as well as listening to and observing others

    after running the script it replace as "CommunFigure  writing, speaking, and showing visuals to other people, as well as listening to and observing others"

    Please help me as soon as possible.I will be very thankfull.

     

    Thanks in advance. 

  • 06-26-2008 6:04 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,194

    Re: Hi how to use find and replace

    Take a careful look at 'mysearch'. It is a list of occurrences. It has no effect on the actual content of the page. It contains things like 'character 1 to 20 of story 1 ....'

    You need another step. Something like (and this is not done in Applescript so will need fixing):

    repeat with textchunk in reverse of mySearch
    set item j of mySearch to "xxx"
    end repeat

    Be sure to use 'reverse of' - if you change characters 1 thru 10 to 'hello', the next reference won't point to an actual occurrence any more!
    I'm a bit too busy to do more than rough this out now, but I hope this helps.
    Emma
  • 06-26-2008 6:12 AM In reply to

    Re: Hi how to use find and replace

    Thank ou very much for your quick reply.Im really very sorry....I didint get you......Please send me the script clearly..... 

  • 06-26-2008 6:20 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,194

    Re: Hi how to use find and replace

    Sorry, I'm hurrying a bit!

    Have a careful look at the variable 'mySearch' and think about what it means to replace it. You are NOT replacing 'character 1 to 5 of story 1' on the Quark page, you are replacing the text 'character 1 to 5 of story 1' in mySearch.

     In the meantime, see if this helps you. It doesn't fix your script but it does work pretty well as a search and replace:

     

    --Put what you want to search for inside the first quotes,
    --and what you want to replace it with inside the second.
    --2 examples are already completed
    --you can add as many of these as you like!

    SAndR("Some text", "some other text")
    SAndR("color", "colour")

    on SAndR(searchstring, replacestring)
         tell document 1 of application "QuarkXPress"
              -- the try...end try bit means it won't error if it doesn't find any instances of a given searchstring
              try
                   set (every text of every story where it is searchstring) to replacestring
              end try
         end tell
    end SAndR




     

  • 06-26-2008 6:33 AM In reply to

    Re: Hi how to use find and replace

    "the municipal transportation authority. In addition to presenting the design (see Figure 1.1), you will want to explain in a proposal"  

     i need to find Figure from my complete quark document and replace Figure 1.1 to Figure 1(have to remove 1.).I am able to understood the problem in my script but i dont know how to solve it. I tried the function you posted,which replaces the whole document.

    Will you please help me.

    Regards,

    Poovili. 

  • 06-26-2008 6:38 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,194

    Re: Hi how to use find and replace

    So do you also need to replace 'Figure 3.4' with 'Figure 3'?

     If it isn't through the whole document, is it just a story? Or just a page? Or what?

     My script can easily be changed so it doesn't do the whole document. But it won't find every 'Figure X.Y' and replace it with 'Figure X', as that would require some sort of wildcard.

    Where is Michel when we need him?? 

  • 06-26-2008 7:04 AM In reply to

    Re: Hi how to use find and replace

     Hi,I need to replace Figure X.Y to Figure X whereever it is present in the document.

  • 06-26-2008 12:11 PM In reply to

    Lightning [li] Re: Hi how to use find and replace

    poovili:
    Hi,I need to replace Figure X.Y to Figure X whereever it is present in the document.
     

    Hi poovili,

    Consider yourself lucky that Emma  specifically requested my help with this. It I had gone with my gutt feeling on this one I would not have responded. Your attitude is just wrong in this case. How dare you DEMAND that she post a complete code especially after she clearly mentioned that she was busy at the time. I understand that you might be in a bind for time and have to respect your deadline and everything but this has NOTHING to do with us.

     That said, the following code should do what you want providing you do not have any anchored element within your text:

     

    001   property MaxFigValue : 100
    002   property MaxFigSubValue : 100
    003   property SearchRoot : "figure"

    004   tell application "QuarkXPress Passport 7.x"
    005      activate
    006      set import styles to true
    007      tell document 1
    008         repeat with s from 1 to count of story
    009            set StoryText to ((path to desktop folder) as text) & "XXX_" & s & ".xtg"
    010            save story s as "XPress Tags" in StoryText
    011            my ProcessText(StoryText)
    012            set story s to file StoryText
    013         end repeat
    014         set OldGuidesShowing to guides showing
    015         set guides showing to false
    016         set guides showing to true
    017         set guides showing to OldGuidesShowing
    018      end tell
    019      beep 3 -- All done!
    020   end tell

    021   on ProcessText(ThisTextFile)
    022      set TheText to (read file ThisTextFile) as text
    023      set TheText to my FindReplace(ASCII character 0, "", TheText)
    024      set TheText to text 3 thru -1 of TheText
    025      repeat with i from 1 to MaxFigValue
    026         repeat with j from MaxFigSubValue to 1 by -1
    027            set SearchFor to (text 2 thru -1 of SearchRoot & space & i & "." & j) as text
    028            set ReplaceWith to (text 2 thru -1 of SearchRoot & space & i) as text
    029            set TheText to my FindReplace(SearchFor, ReplaceWith, TheText)
    030         end repeat
    031      end repeat
    032      set afile to open for access file ThisTextFile with write permission
    033      try
    034         set eof of afile to 0
    035         write TheText to afile
    036         close access afile
    037      on error
    038         close access afile
    039      end try
    040   end ProcessText

    041   on FindReplace(FindWhat, ReplaceBy, ThisString)
    042      copy the text item delimiters to OldDelims
    043      set the text item delimiters to {FindWhat}
    044      set TempList to every text item of ThisString
    045      set the text item delimiters to {ReplaceBy}
    046      set NewString to TempList as text
    047      set the text item delimiters to OldDelims
    048      return NewString
    049   end FindReplace

    Notes: • The line numbers included with this script are there to aid future discussions. In order to use this script, you will have to strip all of them.

    If you have any question, ask nicely!

    Hope this helps! 

    Michel Lemieux
    Click here --> to visit my PUBLISHING & SCRIPTING FORUM

  • 06-26-2008 11:44 PM In reply to

    Re: Hi how to use find and replace

    Hi..Thank you very much for your reply.Now im clear...

    Is there is any possibility of search and replace without import options?if not y it so?

    Y the normal search and replace affect the XTags?

    Thanks in advance. 

     

  • 06-27-2008 12:20 AM In reply to

    Re: Hi how to use find and replace

    poovili:
    Hi..Thank you very much for your reply.Now im clear...

    Is there is any possibility of search and replace without import options?if not y it so?

    Not sure I understand you there. If you mean "Could we do the search and replace within Quark rather than exporting the text and then re-importing it?"

    The answer is yes you could but I stopped trying to figure out how much longer this would take. We are talking about 20 to 30 times slower when done in Quark. 

     

    poovili:
    Y the normal search and replace affect the XTags? 

    Sorry I do not know what you mean by that! 

    Michel Lemieux
    Click here --> to visit my PUBLISHING & SCRIPTING FORUM

  • 06-27-2008 1:27 AM In reply to

    Re: Hi how to use find and replace

    Hi..

    I tried the script send by you in QuarkXPress 6.5..while importing im getting "The import process has been stopped because an invalid tag was found or corrupt information was encountered"...........

     

    How to rectify this error??

     Thanks in advance.

     

  • 06-27-2008 7:05 AM In reply to

    Re: Hi how to use find and replace

     My script should not have any affect on XPress Tags...

    How big is that export? Can you post it here? Can you tell where the invalid tag is located?

    What else can you tell us about your project?  

    Michel Lemieux
    Click here --> to visit my PUBLISHING & SCRIPTING FORUM

Page 1 of 1 (12 items)
Powered by Community Server (Commercial Edition), by Telligent Systems