Tuesday, April 25, 2006

Go get XPress - Part 3

This is the third post of the series. Today's function is getText(aRange), which returns a range of text from the current story. The range parameter is specified in a form { location, length }. Note that the location of the first character of a story is 1, which is AppleScript convention of accessing a list object.

on getText(aRange)
  tell application "QuarkXPress"
    set aLocation to item 1 of aRange
    set aLength to item 2 of aRange
    return text from character aLocation to character (aLocation + aLength - 1) of story 1 of current box
  end tell
end getText

The above code will raise an error if you pass 0 to the length element. As far as Wild CAT is concerned, this is not a problem as it never ask for a null text.

Saturday, April 22, 2006

Go get XPress - Part 2

The second function for our QuarkXPress bridge script is getContentsSize(). This function "returns character length of the text container with focus". Okay, we just get the character length of the current story, right? It goes something like this:

on getContentsSize()
  tell application "QuarkXPress"
    return length of story 1 of current box
  end tell
end getContentsSize

So far, so good.

Friday, April 21, 2006

Go get XPress - Part 1

I introduced "Wild CAT" corpus accessory (guess I forgot to mention the name) in the last post. In the next few posts, I would like to look into a little more detail about the scripts with which the accessory talks to an application.

Here I got QuarkXPress as the target application. Oh, by the way, I am not an AppleScript guru at all. In fact, I am writing this with Bert Altenburg’s AppleScript for Absolute Starters as a reference. So please don't pick nits.

The first function is getContents() which, by definition, "returns whole contents of the text container with focus". What we do is to get the whole text in the current story. Here is a sample code for QuarkXPress:

on getContents()
  tell application "QuarkXPress"
    return story 1 of current box
  end tell
end getContents

You cannot make it any simpler than that?