Applescript problem

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
paulcruice
Posts: 17
Joined: 2006-06-04 15:42:19
Location: Toowoomba, Australia

Applescript problem

Post by paulcruice »

move last paragraph of text of front document to before paragraph (nextParaCount - insertCounter) of text of front document

This line of AppleScript works for all other programs I have; Word X, AppleWorks 6.2.9, but not for NisusWriter Express 2.6.1. NWX trips up on understanding the word BEFORE. Obviously this is a NWX problem NOT an AppleScript problem. Is there anything I can do to rewrite this so that it works?
Thanks.
Last edited by paulcruice on 2006-06-05 14:00:27, edited 1 time in total.
Jesus heals the rift between Man and Creator.
dshan
Posts: 334
Joined: 2003-11-21 19:25:28
Location: Sydney, Australia

Post by dshan »

I assume there is more to the script than just this line? We need to see the whole script to help (or even reproduce the problem). Just because a script points to a particular line as an error doesn't always indicate the error is in that line, it may be triggered by a problem elsewhere in the code.

You say you've used this line in scripts for various other apps, but what about the rest of the script? Are they all the same or does the NWX script differ from the others in some way?

Also, simply saying it "trips up" is not much use in determining the nature of your problem. We need to see the exact text of the error message(s) you get when running the script.
paulcruice
Posts: 17
Joined: 2006-06-04 15:42:19
Location: Toowoomba, Australia

Post by paulcruice »

dshan,
Thanks for the quick reply.
Here is the complete script and yes, it is the same script used in all apps except of course for the relevant app.
The script is designed to reorder paragraphs e.g. I have a document with 6 paragraphs, ABC123 where ABC are 3 Greek paragraphs and 123 are the 3 English translations. I want the paragraphs reordered as A1B2C3. In other words, I want each Greek verse followed by its corresponding English translation.

tell application "Nisus Writer Express 2.6.1"
activate
set paragraphCount to count (text of front document) each paragraph -- set paragraphCount variable to number of the paragraphs in Doc 1, must be an even number.
set insertCounter to 1 -- set insertCounter variable to start at 1
set repeatCounter to (paragraphCount / 2) -- used to set the number of repeat cycles.
set nextParaCount to (repeatCounter + 2) -- used in locating the next point of paragraph insertion.
repeat repeatCounter times
move last paragraph of text of front document to before paragraph (nextParaCount - insertCounter) of text of front document -- move the last English paragraph in the document to the position immediately following the relevant Greek verse.
set insertCounter to insertCounter + 1 -- set insertCounter to enable correct determination of next paragraph insertion point
end repeat
end tell

Cheers.
Jesus heals the rift between Man and Creator.
dshan
Posts: 334
Joined: 2003-11-21 19:25:28
Location: Sydney, Australia

Post by dshan »

Thanks for that script. When I run it against NWX with text:

Para A
Para B
Para C
Para 1
Para 2
Para 3

It gives no errors, but produces the output:
Para A
Para B
Para C

i.e. It deletes the last three lines/paragraphs. Is this what you meant by saying it "trips up on understanding the word BEFORE"?

I tested the same script using AW 6.2.9 and it gives:
Para A
Para 1
Para B
Para 2
Para C
Para 3

Which seems to be what you are after. I also tested it using TextEdit and it deleted the last three paragraphs, just like NWX.

The problem appears to be that NWX (and TextEdit) do not support the index property for paragraphs whereas AW does. It's not the BEFORE that is causing the problem but the "paragraph (nextParaCount - insertCounter)" reference, I think. You can check this by dragging the NWX/AW app onto the Script Editor app and checking the Text Suite and AppleWorks Text Suite properties for paragraphs they support -- no index property is listed for NWX whereas it is for AW.

As it says in the NWX User Guide and help files under AppleScript macros:
'Nisus Writer Express also supports part of the Text Suite and the "Do Menu Macro" command.' Only part of the Text Suite alas...
paulcruice
Posts: 17
Joined: 2006-06-04 15:42:19
Location: Toowoomba, Australia

Post by paulcruice »

dshan,
Thanks. Yes, the outcome you got is my experience and what I meant by "trips up..." and yes it is the AW outcome which I require.
I understand the lack of the paragraph index property and will now take it to Nisus Support.
Many thanks for your time and effort to help.
Jesus heals the rift between Man and Creator.
Post Reply