Microsoft Word: Make Numbers in Selected Text Superscript Without Affecting the Words

I love Keyboard Maestro and use it for simple things. But I have something complex I need to do, but cannot figure out how best to accomplish it. I would be really grateful if somebody could help,

My daily workflow means that I paste bible scriptures into Microsoft Word continually. I have a service defined to pull the scriptures from my bible programme and insert them into Word.

The bible scriptures can only be exported with no formatting (this has been verified).

Here is the problem,,, each bible verse begins with a verse number. I need all those verse numbers to be superscript and it takes a long time to do this manually.

Can somebody help me figure out how to set up a macro in KM that enables me to convert any numbers in selected text in Word to superscript numbers, without affecting the rest of the text?

Thank you for any help you can give...

Nick

Post some examples of exactly what text is copied.

Here is an example. I want all the bible verses to be superscript!

Thank you for your help!

1 In the beginning God created the heavens and the earth. 2 The earth was without form, and void; and darkness was on the face of the deep. And the Spirit of God was hovering over the face of the waters. 3 Then God said, “Let there be light”; and there was light. 4 And God saw the light, that it was good; and God divided the light from the darkness. 5 God called the light Day, and the darkness He called Night. So the evening and the morning were the first day. 6 Then God said, “Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.” 7 Thus God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament; and it was so. 8 And God called the firmament Heaven. So the evening and the morning were the second day.

This action will go through the text on the clipboard and find each sequence of one or more digits and apply a superscript type to it:

Note that by applying any style, you necessarily get styled text, which means the font will be defaulted to something, probably Helvetica 12 so that will no longer simply take up the font/size of the target text like plain text would.

For Each.kmactions (1.5 KB)

3 Likes

Great solution, Peter. I don't think I would ever have thought of this approach.
Learned something new about the "For Each" Action.

1 Like

That’s perfect! Many thanks!

1 Like

Not sure how this works but it does. Solves my request. Thank you.

Sorry for replying to this old post, but just made a macOS service that does this. And was wondering if I should spend sometime converting it into an Keyboard Maestro action?
https://bibleformat.webflow.io the macOS service is made with JXA so it should be possible to rewrite it if it's relevant?

1 Like

Hey Andreas,

Welcome to the forum!   :smile:

I'm not sure how that would work with JXA – maybe find/replace with the Number/Unicode-Value?

In any case – Keyboard Maestro can run JXA directly, and it also has a very strong search/replace action.

So it would be interesting to see it running in KM.

-Chris

Hi @ccstone,

Thanks for the welcome! But admit I haven't used KM really before, have many tried but always loved the idea and now I love the Macro builder!

Just tried make the Bible Verse Formatter into a Macro, and so far I think it works...

Haven't really tested it out many places. But please feel free to come with feedback!

Will add it later to the website then it can be downloaded from there too.

Bible Verse Formatter Beta 1.kmmacros (26.0 KB)

So it uses the clipboard not sure if there is a better way to get selected text?

Hey Andreas,

Looks good.

Well done!

You can in Microsoft Word using AppleScript, but using the clipboard will be more versatile across other applications that aren't AppleScriptable.

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/09/14 03:29
# dMod: 2021/09/14 03:29
# Appl: Microsoft Word
# Task: Get Selected Text
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Microsoft_Word, @Get, @Selected, @Text
--------------------------------------------------------

set theText to getSelectedTextFromWord()

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on getSelectedTextFromWord()
   tell application "Microsoft Word"
      return content of selection
   end tell
end getSelectedTextFromWord
--------------------------------------------------------
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/02/12 13:24
# dMod: 2021/02/12 13:24 
# Appl: Microsoft Word
# Task: Set Selection to Text
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Microsoft_Word, @Set, @Selection
--------------------------------------------------------

set theText to "Now is the time for all good men to come to the aid of their country."

setWordSelectionToText(theText)

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on setWordSelectionToText(theText)
   tell application "Microsoft Word"
      set content of selection to theText
   end tell
end setWordSelectionToText
--------------------------------------------------------

-Chris

Cool Chris, maybe not so flexible then, would love it to be used as many places as possible. Will try to stick with the Clipboard for now then. :+1:t3:

1 Like

Is there a way to not have this macro change the font?

The macro sets the superscript just fine. BUT. it changes the font. I use Schoolbook and that is not on the dropdown list of available fonts.

Am I missing something here?

  1. What app are you copying from?

  2. Are you pasting back into the same app?

  3. Is the SchoolBook font installed on your system and available to other apps?

| ccstone
March 23 |

  • | - |
  1. What app are you copying from?

Microsoft word on MacBook pro m1

  1. Are you pasting back into the same app?

Yes

  1. Is the SchoolBook font installed on your system and available to other apps?

Yes use it a lot.

to CCStone: Not thinking clearly. I am using this macro with Pages. not Word.