in

Quark Forums

Applescript text box searching. Possible bug? Text not found after 235 characters.

Last post 08-11-2009 8:00 PM by WeatherGraphics. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 07-22-2009 12:37 AM

    Applescript text box searching. Possible bug? Text not found after 235 characters.

    We have a script that searches and replace text within text boxes on a page that seems to have a bit of trouble when the text occurs too deep into the text box.

    If the text occurs within the first 235 characters, no problem.  After that, no chance!

    We are trying to compile a list of text box object reference to allow processing of the located text.

    Identifying the text on the page works:

                count of (every text of every text box where it is beginTag) -->This works
                count of (every text box whose every text contains beginTag) -->This doesn't

    But getting the object reference of the text boxes that contain the text does not seem to be so simple:

                set allTextBoxes to (object reference of every text box whose every text contains beginTag) --> Works if text is in the top of the box!

    It appears to be the 'contains' part of the script that introduces the problem.  And we have so far been unsucessful at finding a syntax that works.

     Anyone else been here before us?

     Cristian..

     

  • 07-22-2009 9:57 AM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Hi Christian,

    That 235 character limit seems odd to me and is probably due to something else you haven't considered.

    Whenever you "Replace" or "Remove" text  from text boxes, it is best to work your way back from the end.

    The reason is this: Your text references (calculated before any text replacement occurs) are in the form of:

    text from character x to  character y of  story w ... and they DO NOT actualize as your script change or delete text. In order to have this work going "forward" in the list you have to make sure that you do not change the length of those text references. Reading your post, this does not seem to be the case and this actually breaks every text references that follows the one your script is currently working on.

    EXAMPLE:

    Story 1: "123456789012345678901234567890"

    Script:

     

    001   tell application "QuarkXPress Passport"
    002      tell document 1
    003         get text of story 1
    004         set TextRefs to object reference of every text of story 1 where it is "567"
    005         repeat with i from 1 to count of TextRefs
    006            log "Pass " & i
    007            try
    008               set text of item i of TextRefs to ""
    009               get text of story 1
    010            on error errText
    011               log errText
    012            end try
    013         end repeat
    014      end tell
    015   end tell

    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.

    Result:

     

    001   -- started
    002   tell application "QuarkXPress Passport"
    003      get every text of story 1 of document 1
    004      -->   "123456789012345678901234567890"
    005      get object reference of every text of story 1 of document 1 whose it = "567"
    006      -->   {
    007            text from character 5 to character 7 of story 1 of document "Project2",
    008            text from character 15 to character 17 of story 1 of document "Project2",
    009            text from character 25 to character 27 of story 1 of document "Project2"
    010         }
    011      (*Pass 1*)
    012      set every text of text from character 5 to character 7 of story 1 of document "Project2" to ""
    013      get every text of story 1 of document 1
    014      -->   "123489012345678901234567890"
    015      (*Pass 2*)
    016      set every text of text from character 15 to character 17 of story 1 of document "Project2" to ""
    017      get every text of story 1 of document 1
    018      -->   "123489012345671234567890"
    019      (*Pass 3*)
    020      set every text of text from character 25 to character 27 of story 1 of document "Project2" to ""
    021      (*QuarkXPress Passport got an error: Can’t set every text of text from character 25 to character 27 of story 1 of document "Project2" to "".*)
    022   end tell
    023   -- stopped

    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.

    As you can see, the first pass did what we wanted it to.

    The second however, deleted "890" instead of the intended second "567". That is because, considering the actual story, after pass 1, text from character 15 to character 17 now refers to "890".

    On the third pass, the script breaks because Quark can no longer determine what  text from character 25 to character 27 asthe story is now only 24 characters in length.

    Working your way backward side step this land mine.

     

    HTH

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

  • 07-22-2009 6:25 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Ace,

     Thanks for the reply.  I probably should have mentioned that the remainder of the script, the part that actually does the replacement of the text, does in fact work in the manner you describe, from the bottom up, so as to preserve the text references.

     The first couple of lines of text :

                count of (every text of every text box where it is beginTag) -->This works
                count of (every text box whose every text contains beginTag) -->This doesn't

    Identify when a page actually contains text that needs replacing.  Our original Mac OS9 / Quark 4 script used the second line and worked fine, but when we moved to Quark 7 and Mac OSX we needed to modify the code to the first line in order to see text beyond 235 characters.  Which I can assure you is a very real problem at our end.  Just running the above two lines of text on a text box with than 235 characters and ID text at the beginning and end gives the following results:

    tell application "QuarkXPress"
        count every text of every text box of page 1 of document 1 whose it = "<A:"
            2
        count every text box of page 1 of document 1 whose every text contains "<A:"
            1
    end tell

    Is there something I am missing, or are the two lines of code behaving differently? Neither are doing anything but interogating the text box.

    The above lines of code are used to identify pages that actually require text replacement, then next line of code should compile a list of object references for text boxes on the page that need text replacement, to pass to the handler that actually does the text replacement:

                set allTextBoxes to (object reference of every text box whose every text contains beginTag) --> Works if text is in the top of the box!

    This code will not see past 235 characters, and we have been unable to find an alternate syntax that will.

    Thanks again for your help on this, we have been pulling our hair out over it for a while, and conjuring up some rather unattractive code work arounds to eliminate the side effects.

    Cheers,

    Cristian..

     

  • 07-22-2009 6:55 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Hi again,

    Perhaps if I knew what you were after or see actual documents...

    For instance, I cannot see why I would ever use a "whose EVERY text contains...", to me it does not sounds right.

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

  • 07-22-2009 7:21 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

    Ace,

    We use a form of markup to replace large amounts of data on Quark Template pages on a daily basis from Excel spreadsheets.  The Markup tags are of the format:

    <A:Excel Spreadsheet.xls:RangeName>

    The script in question is run at regular intervals throughout a day on the same set of Quark documents and batch processes a large number of pages, replacing tag text as excel ranges are filled with data over same day, but upon opening a quark page it interogates the document to see if there are tags existing, it does this by searching every textbox on the page using:

    count of (every text of every text box where it is beginTag)

    Where beginTag is '<A:', if it finds this string on the page (ie count > 0) it proceeds to identify which idividual text boxes contain the string using:

    set allTextBoxes to (object reference of every text box whose every text contains beginTag)

    Which builds a list of object references for text boxes that contain the string.  It then cycles through that list one text box at a time identifies all the tags in the box, and then attempts to replace them if data exists in the spreadsheet.  

     We had to remove the 'whose every text contains' from the first line of code as it was not seeing past 235 characters, but we have not been able to come up with an equivalent to the second line of code that will compile a list of object reference for every text box on a page that contains the string '<A:'without using the 'whose every text contains'.

     Pretty complicated, but the script has served us well for almost a decade now with only slight tweaking.

    If you need to see any scripts, let me know, I can post them up, they are quite large, and I was trying to keep it simple!

     Thanks again,

     Cristian..

  • 07-22-2009 8:44 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Could this help?

     

    001   tell application "QuarkXPress Passport"
    002      set docName to name of document 1
    003      tell document docName
    004         set StartTags to object reference of every text of every story where it is "<a:"
    005         set BoxListIDs to {} -- List of text box UniqueID's that contains your start tag
    006         set BoxListRefs to {} -- List of every text box references that contains your start tag (may contain duplicate)
    007         repeat with ThisTag in StartTags
    008            set ThisBoxID to uniqueID of text box 1 of ThisTag
    009            if BoxListIDs does not contain ThisBoxID then
    010               set end of BoxListIDs to ThisBoxID
    011            end if
    012            
    013            set end of BoxListRefs to object reference of text box 1 of ThisTag
    014            
    015         end repeat
    016      end tell
    017   end tell
    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.

    With this you do get a list of every text box that contain your Start Tags (from 2 different POV)

     

    HTH

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

  • 07-23-2009 12:18 AM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Ace,

    An elegant solution, definitely compared to ours!

    But try this with more than 235 characters in the text box, and the search string spread throughout and tell me if you get the same result.

    property beginTag : "<A:" as string

    tell application "QuarkXPress"
        set docName to name of document 1
        tell document docName
            set allTextBoxes to (object reference of every text box whose every text contains beginTag) --> Works up to 235 chars!
           
            set StartTags to object reference of every text of every story where it is beginTag
            set BoxListIDs to {} -- List of text box UniqueID's that contains your start tag
            set BoxListRefs to {} -- List of every text box references that contains your start tag (may contain duplicate)
            repeat with ThisTag in StartTags
                set ThisBoxID to uniqueID of text box 1 of ThisTag
                if BoxListIDs does not contain ThisBoxID then
                    set end of BoxListIDs to ThisBoxID
                end if
               
                set end of BoxListRefs to object reference of text box 1 of ThisTag --as list
               
            end repeat
        end tell
        display dialog BoxListRefs
    end tell

    We would still need to sift out the duplicates from the obove code, as we only want to work on each box once, and there may be hundreds of instances in each text box.

    Not too mention the 1 line of code that replaces 15, kind of.  Well at least it did under Quark 4 and OS9.

     It seems a bit of a backwards step, and it seems odd that it would work with less than 235 chars in the text box, but not above.  I guess I would feel a bit better if someone else tried it and said, "yeh, you are right, that is what happens!"

    Cristian..

  • 07-23-2009 6:17 AM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Here are my results for the StartTags list:

    {
       text from character 679 to character 681 of story 1 of document "Project2",
       text from character 2538 to character 2540 of story 1 of document "Project2",
       text from character 6847 to character 6849 of story 1 of document "Project2",
       text from character 10292 to character 10294 of story 1 of document "Project2",
       text from character 13842 to character 13844 of story 1 of document "Project2",
       text from character 15369 to character 15371 of story 1 of document "Project2",
       text from character 679 to character 681 of story 2 of document "Project2",
       text from character 2538 to character 2540 of story 2 of document "Project2",
       text from character 6847 to character 6849 of story 2 of document "Project2",
       text from character 10292 to character 10294 of story 2 of document "Project2",
       text from character 13842 to character 13844 of story 2 of document "Project2",
       text from character 15369 to character 15371 of story 2 of document "Project2"
    }

    As you can see, there doesn`t seem to be a 235 character limit...

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

  • 07-23-2009 5:59 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

    Ace,

    What results did you get for the allTextBoxes list under the same conditions?

    Because this is where I see the differences.  This is why I believed it to be a bug, one line of code that use to work in older versions of software, behaves completely differently and needs to be replaced with 10+ lines of code in newer versions.

    Not only that, but if you, like we did, tested the code using text boxes with less than 235 characters you would never have been able to creat the error in the first place.

    Cristian..

  • 07-23-2009 9:26 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Well, I did not go there since I could build that list otherwise.

    Like I said, I find this construct very strange and I would never expect it to work for me anyhow.

    As for it working in older version, Quark has been through a complete rewrite with v6 and lots of scripts got broken because of that.

    In any case, it now appears that you can make your script works by inserting that code of mine.

     

    HTH

     

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

  • 07-23-2009 11:01 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

     Ace,

    I do not want to sound ungrateful, because I really do appreciate any and all assistance I get from this and others forums, but two things:

    Firstly, could you actually explain why you consider the construct to be strange.  As all we are aiming to do is compile a list of Text boxes in which the string appears, and not every individual instance of the string, it does not necessarily look like strange syntax to me.  Despite the fact that it obviously does not work ;)

     Secondly,  we could definitely use your code, though we do have a similar work around code that does produce the required result, which from your above example would be:

    {

    text box 1 of page 1 of document "Project2",
    text box 2 of page 1 of document "Project2"

    }

    We would have to filter out all duplicates, and isolate just the object reference of the text box, the text reference is of no importance.

    Truly thank you for helping me out with this!

    Cristian..

  • 07-24-2009 8:20 AM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

    WeatherGraphics:

     Ace,

    I do not want to sound ungrateful, because I really do appreciate any and all assistance I get from this and others forums, but two things:

    Firstly, could you actually explain why you consider the construct to be strange.

    As all we are aiming to do is compile a list of Text boxes in which the string appears, and not every individual instance of the string, it does not necessarily look like strange syntax to me.  Despite the fact that it obviously does not work ;)

     

    I find it starnge because "text" (in Quark's view) is not a finite entity as opposed to words or paragraphs for instance.

    Now consider the following statement:

    set RefList of object reference of every text of every story where it is "foo"

    This will returns a list of occurances of the the string foo whitin every story of your document (each item being in the for of: text from character x to character y of story z of document 1)

    So TEXT is simply a string that has no delimiter other than the one you specify. Reading this, it stand to reason that there are other TEXT within those stories BUT my script chose to ignore them.

    Now, on to your construct:

    set allTextBoxes to (object reference of every text box whose every text contains beginTag)

    What I do find peculiar, as I mentioned before, is the use of EVERY TEXT CONTAINS. Since we know there are an infinite number of TEXT within a story. Asking to get a list of text boxes whose EVERY TEXT contains certain character is very strange to me.

    Let say you are at the market and come accross boxes containing fruits. If you wanted to get the boxes that contains apples you would not ask the farmer:

     Please tell me which box whose EVERY fruit is an apple?

     If he does not have a box ONLY filled with apples, he will simply say "I have none".

    WeatherGraphics:

    Secondly,  we could definitely use your code, though we do have a similar work around code that does produce the required result, which from your above example would be:

    {

    text box 1 of page 1 of document "Project2",
    text box 2 of page 1 of document "Project2"

    }

    We would have to filter out all duplicates, and isolate just the object reference of the text box, the text reference is of no importance.

    Truly thank you for helping me out with this!

    Cristian..

     

    Than you should use the part of the code that deal with UniqueID. Your previous code worked with standard text box reference like the ones you just mentioned BUT you can also use its UniqueID for the "targetting" process. 

    Now my BoxListIDs does rmove duplicates and you could use it to target each box only once

    OR

    You could also go through the BoxListRefs (which MAY congtain duplicates) and at the start of each iteration check to see if its UniqueID has already been processed:

     

    001   set Processed_IDs to {}
    002   repeat with ThisBox in BoxListRefs
    003      set BoxID to uniqueID of ThisBox
    004      if Processed_IDs does not contain BoxID then
    005         -- do your stuff here
    006         set end of Processed_IDs to BoxID
    007      end if
    008   end repeat

    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.

     

    HTH

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

  • 08-11-2009 8:00 PM In reply to

    Re: Applescript text box searching. Possible bug? Text not found after 235 characters.

    Ace,

    Thanks, I guess I will just have to accept that the more economical code that use to work, and that still works with less than 235 characters in a text box, is just a cruel co-incidence, to trick us into thinking it should work. And that your code is our only way around it.

    For the record though, re your box of fruit analogy, you are missing the crucial word here "Contains", the question would not be?

    Please tell me which box whose EVERY fruit is an apple?

    It would be:

    Please tell me which box whose EVERY fruit contains an apple?

    Meaning he would give me every box that contains 1 apple or more, which is actually what we want!

    Cristian..
Page 1 of 1 (13 items)
Powered by Community Server (Commercial Edition), by Telligent Systems