Reformatting Quark files

I work as a layout designer for a couple of magazines in Italy.
I spend most of the time re-formatting texts according to our styles (i.e. bold, italic, plain text, etc).
Is it possible to create a script that analizes a series of linked text boxes, if it encounters a " or a << it switches to a character style like italic, then when it encounters " again or >> it switches back to plain text again?
Maybe a bit confusing, but I know you can understand…:wink:

Eeeh… yes. Quite confusing. Can you specify a bit more or give examples?

Ok, sorry.
I’ve got a long interview, right? I want the script to “read” the article and change to a predefined character style everything between “ and ” (or << and >>), in other words, everything the interviewed actually said has to be quoted in character style “Italic”.
Hope this throws a ray of light on my words…

I’m sure there is a much more elegant way of doing this using object references but in limited testing, this works:

tell application "QuarkXPress? 4.11"
        tell document 1
            repeat with i from 1 to (count of stories)
                tell story i
                    set the_offsets to my get_offsets(contents, "?", "?")
                    repeat with this_offset in the_offsets
                        set style of (text from character (item 1 of this_offset) to character (item 2 of this_offset)) to italic
                    end repeat
                end tell
            end repeat
        end tell
    on error the_error
        display dialog the_error
    end try
end tell

on get_offsets(the_string, start_delim, end_delim)
    set {the_offsets, temp_string, last_position} to {{}, the_string, 0}
            set this_start to (last_position + (offset of start_delim in temp_string))
            set temp_string to (text this_start thru -1 of the_string)
            set this_end to (this_start + (offset of end_delim in temp_string))
            set temp_string to (text this_end thru -1 of the_string)
            if last_position = this_end then
                exit repeat
                set end of the_offsets to {this_start, this_end}
                set last_position to this_end
            end if
        on error
            exit repeat
        end try
    end repeat
    return the_offsets
end get_offsets

I imagine large stories will probably result in stack overflows if run in OS 9.


Although I am not such a script master and Jonn’s solution may work, I think it’s good to take a look here. In my opinion quark is pretty slow in doing this kind of jobs.
For the magazines I am working on I drop the text in to a folder with an action to convert RTF-files to XPress tags (but I still have some problems with superscripts). Import these text-files in Quark and you can do the job you really want to do (eeh, designing?). This can save you even more time when you add some style sheets.

That sounds good, actually.
But what if I want to apply not just the italic, but a character style called “Italic”? Or Bold or whatever?
Do the xpress tags come in help in this case or not?

Sure. That’s possible. Let the script search for " or << and replace it by
and, to mark the end of the character style search for
" or >> and replace it by
"<f$> or >><f$>
instead of <f$> you can also paste the name of the next style sheet.

Best way is to export a styled text from Quark to Quark Xtags and than open the file in a text editor to see how the tags look like. There will be a lot of crap in the beginning, but I skip that and make sure to paste style sheet Normal before the first paragraph. In Quark, Normal is specified as the body text.

Everything you are trying to do is easily accomplished manually by using Quark’s Find/Change command…And it’s fast.