Final: QuarkXpress: Gettings words
Final: QuarkXpress: Gettings words
- Subject: Final: QuarkXpress: Gettings words
- From: ThK <email@hidden>
- Date: Thu, 12 Jul 2001 17:19:16 +0200
Ok,
This was posted to me. I think you all should know. The solution has been once posted in this list.
Thomas
---------------------------------->
>
Problem:
>
>
Quark returns "earth" when it is asked for "word x of line y of text
>
box z of document d" and it was "earth." because it was the end of a
>
sentence.
>
>
But i need "earth." when it is "earth." and "earth" when it is "earth"!
>
>
The background ist, that my script has to recognize prices,
>
measurements and sizes that have to be converted into another
>
language and format replacing the original word or words.
>
>
Does anyone have an idea how to force this?`
Thomas,
The clue is in Quarks delimit tables. I got these two replies from
QuarkXPress script guru Hans Haesler when I asked the following on
this list some time ago. If you study his brilliant answers, you will
find what you need.
Hope this is of any help,
Hevard
First I asked this:
>
>>I am working on a script applying style specs to text in quark. I
>
>>need my script to recognize empty lines so I had something like
>
>>if paragraph x of selection is "" then ....
>
>>which failes on some lines as quark seems to return "" when
>
>>paragraphs does meet certain criterias.
>
>>
>
>>If I make a text-box in a quark doc, and type the following three
>
>>lines of text in it:
>
>>()"#%&/=!!!
>
>>
>
>>()"#%&/=!!!test
>
>>
>
>>select it and run this:
>
>>
>
>>tell document 1 of app "QuarkXPress Passport 4.11"
>
>>tell current box
>
>>repeat with i from 1 to count paragraphs
>
>>paragraph i
>
>>end repeat
>
>>end tell
>
>>end tell
>
>>
>
>>count every paragraph of current box of document 1
>
>>--> 3
>
>>get paragraph 1 of current box of document 1
>
>>--> ""
>
>>get paragraph 2 of current box of document 1
>
>>--> ""
>
>>get paragraph 3 of current box of document 1
>
>>a--> "()\"#%&/=!!!test"
>
>>
>
>>quark returns the first line as "" and not "()"#%&/=!!!" as I
>
>>would expect. Is this a feature I can turn off, or get around?
>
>>
>
>>Hevard
Then Hans replied:
>
>Havard,
>
>
>
>please select your box with the three paragraphs and run this:
>
>---
>
>tell document 1 of application "QuarkXPress 4.11"
>
> tell current box
>
> get word 1
>
> end tell
>
>end tell
>
>---
>
>The result is "test". Surprised? I think so.
>
>
>
>Next run:
>
>---
>
>tell application "QuarkXPress 4.11"
>
> delimit items of delimit table 1
>
>end tell
>
>---
>
>The result is a list of 256 items with constants like:
>
>{not word member, can start or end word, can be contained in word,
>
>can start or end or be contained in word}
>
>
>
>The list covers the characters from ASCII 1 through 255.
>
>
>
>To get the value for one character you run:
>
>---
>
>tell application "QuarkXPress 4.11"
>
> get delimit item "(" of delimit table 1
>
>end tell
>
>--> not word member
>
>
>
>You may change the constants for every character, but I think
>
>this would not be a good idea.
>
>
>
>To get around of getting an empty string for your first paragraph:
>
>---
>
>tell document 1 of application "QuarkXPress 4.11"
>
> tell current box
>
> set paraOne to text from character 1 to character -2 of paragraph 1
>
> end tell
>
>end tell
>
>-->"()\"#%&/=!!!"
>
>
>
>HTH,
>
>
>
>Hans
And a bit later corrected himself to:
>
On Sat, 18 Nov 2000, I wrote:
>
>
>The list covers the characters from ASCII 1 through 255.
>
>
Sorry... this should be "... from ASCII 0 through 255."
>
>
The constant for every character can be get by using the ASCII number.
>
Even for ASCII zero, although an item 0 is impossible (XPress adds 1
>
to make it work):
>
---
>
tell application "QuarkXPress 4.11"
>
delimit item 0 of delimit table 1
>
end tell
>
-->not word member
>
>
As I said before, it's not a good idea to fiddle with the items of the
>
delimit table. You must have a good reason for doing it. Okay, the table
>
is restored to the defaults when you restart XPress, but you should save
>
the list of the constants und restore the table at the end of the script.
>
>
Below an example for your three-paragraph text box. The script saves
>
the list, sets every item to 'can start or end or be contained in word',
>
loops through the items 0 to 32 to reset them to 'not word member',
>
gets the contents of paragraph 1, restores the delimit table and
>
displays a dialog.
>
>
While you can set every item of the table to one constant in one sweep,
>
you must loop through them to restore the values.
>
---
>
tell application "QuarkXPress 4.11"
>
set oD to delimit items of delimit table 1
>
set delimit items of delimit table 1 to can start or end or be
>
contained in word
>
repeat with i from 0 to 32
>
set delimit item i of delimit table 1 to not word member
>
end repeat
>
tell document 1
>
tell current box
>
set paraOne to paragraph 1
>
end tell
>
end tell
>
repeat with i from 1 to 256
>
set delimit item (i - 1) of delimit table 1 to item i of oD
>
end repeat
>
display dialog paraOne
>
end tell
>
-->"()\"#%&/=!!!"
>
>
The timings (one run, no average): from Script Editor = 2100 ticks,
>
from OSA Menu = 72 ticks.
>
>
Hans
<-----------------------------------