Reformatting Quiz Questions with Regular Expressions (RegEx)

Hi there,

I've created a macro which does all this formatting for me (i.e. deleting spaces and unwanted text). It's super helpful and saves heaps of time. However, I have to trigger it for each paragraph.

Is there a way that the macro can work through the document and stop when it gets to the end of the document?

I can't use the 'repeat' action because I don't know how many times the action needs to repeat. Even if I was to count the paragraphs, each document would be different.

Any help or advice would be greatly appreciated.

Kind Regards

Aaron

Hey Aaron,

What application are you working in?

-Chris

You might be able to get the location in the document you are in using AppleScript. Many apps document object support that.

It really would help to know what app this is the (as @ccstone asked).

Hi Chris and Johns,

Thank you for your replies. I’m using the macro in Microsoft Word for Mac. Alternatively, I could use text/edit, if that can help achieve the desired result.

Many thanks

Aaron

Pages (Mac) is closer to Word in functionality, and is highly scriptable (via AppleScript).

You can definitely get the document, and you can iterate over 'paragraphs' as well.

Hey Aaron,

Are you working with styled text or plain text?

-Chris

Hi Chris,

At the moment it is styled text but ultimately I convert the file to plain text (hence why I can work in Word or text/edit).

Cheers

Aaron

Hey Aaron,

Okay, if you can work with plain text then you're presently doing things the hard way.

You either want to massage the text directly in Keyboard Maestro, or in a very scriptable app like the free (or paid) version of BBEdit.

Give us the rundown on how you're massaging your text and then we can advise on the best method.

-Chris

Thanks Chris for looking into this!

I start with text like this....

  1. When the offeror insists that the offeree accept the offer by telephone, the offeree:

A. Can accept the offer in any way.
B. Can accept the offer by telephone or by any other means of instantaneous communication.
*C. Must accept the offer by telephone.
D. Can accept by post according to the postal rule.

General Feedback:
Learning Objective 7.2: When does a contractual agreement come into existence? What is an offer? Is an advertisement an offer? What is an acceptance? When is it effective?

Which needs to formatted like this....

When the offeror insists that the offeree accept the offer by telephone, the offeree:
A. Can accept the offer in any way.
B. Can accept the offer by telephone or by any other means of instantaneous communication.
*C. Must accept the offer by telephone.
D. Can accept by post according to the postal rule.
ANSWER:

I do this using this macro Quiz macro keys.kmmacros (16.0 KB)

I want to run this macro for all the questions, of which there may be 50-80 (depending on the topic).

I hope this makes sense. Your help is much appreciated.

Cheers

Aaron

Hey Aaron,

Can you provide a larger sample of questions? Or a whole quiz (before and after)?

When parsing text you have to see good real-world examples, or it's all to easy to fumble the ball and waste a lot of time.

-Chris