Some Touch Bar Buttons/Widgets for Microsoft Word: font style, size, color, alignment, highlight

I made some AppleScript buttons/widgets for Word. The preset includes:

  • button for saving. Button is gray as long as there haven't been any changes since the last save
  • bold/italc/underlined buttons. They are highlighted if the selected text is bold/italc/underlined
  • buttons for increasing and decreasing font size and, just for fun, a slider widget for adjusting the font size
  • alignment buttons. Highlighted according to the alignment of the selected paragraph
  • Widgets for highlighting text and changing the font color


Only tested with Word 16.31 (Office 2019)

I would suggest only activating some of those widgets and/or increasing the "Execute script every X seconds" for battery reasons.

Something useful I discovered which is not included in the preset:
In the word menu, under extras, you can "adjust keyboard", meaning you can create your own hotkeys for some functionalities. For exaple, this can be used to create a Touch Bar widget that shows wether the style of the current paragraph is "Normal" and msets the style to "Normal" upon pressing the button. Use this code for the appearance of the widget:

if application "Microsoft Word" is running then
tell application "Microsoft Word"
return name local of style of selection
end try
end tell
end if

Set the Alternate Color Regex to "Normal". Then set a hotkey for toggling the "Normal" style in the Word settings. Now assign this hotkey as the action of the widget.

Thank you very much for writing and sharing this. I've been struggling immensely to get my computer to be less of a hindrance and more of a help.

I don't really know anything about coding etc.... but I managed to get some of your presets to work for OneNote by just changing "Microsoft Word" to "Microsoft OneNote". If it is possible, is there any chance can you help me to change your presets for changing font size to work for OneNote please?

I know OneNote doesn't have the increase/decrease font size things like Word. Perhaps it would be possible to make a few buttons for preset font sizes?

I would really appreciate any help but don't feel obligated to - just the fact that I've managed to get many of the things I use over and over onto the Touch Bar due to your presets is like a second Christmas.

Hey, I'm happy to hear that you like the preset. I just checked and unfortunately, OneNote does not offer an AppleScript dictionary (you can check in the script editor app under File > Open Dictionary). I didn't find much on AppleScript and OneNote on google either. So I'm afraid I don't know how to help you.

If, as you said, some of the buttons work with OneNote though, OneNote seems to support AppleScript in general, so it might be possible somehow.

Thank you for the response!

It seems I was mistaken though. Like I said, I changed the scripts from "Microsoft Word" to "Microsoft OneNote" and the BTT was happy to accept the scripts but when I actually tested I didn't test the ones that use your scripts - I tested the ones that simply press keyboard shortcuts. Silly of me.

Thank you though - I'm still using your preset for Word, it's immensely useful.

1 Like

Can you make some AppleScript buttons/widgets for Microsoft PowerPoint?

I don’t think I will do that, sorry

any suggestions about timings?

I would use two or three seconds, so it still feels kind of fast responding. Another thing i would recommend is assign another action to the buttons, which refreshes the button via the UUID, as described here: Touch bar widget: Trigger run script when touch button is touched to speed up alternative icon changes
(Get the UUID by right-clicking the trigger and clicking "copy selected item UUID".)
This way your buttons will refresh automatically everytime you press them. It might take a couple of minutes to understand and set up, but it should be worth it.

you are asking very much of me - I am really lost with all that coding stuff :-))

I see how it looks complicated but it is actually pretty simple :slight_smile: Ill try to explain. If you for exaple want to do it for the "bold" button:

right click the "bold" button in the BTT trigger list and click "copy selected item UUID". (The UUID is a series of numbers & letters which is unique for every trigger). It is now in your clipboard.

In the list of the actions that are assigned to the "bold" button, click on the "+" to assign a new action. Choose "Run Apple Script (async in background)" as the type of the action.

Insert this code where it says "#Insert script code here":

tell application "BetterTouchTool"
end tell

but instead of the Xs, insert the UUID that you copied.

That should be it. Now, everytime you press the "bold" button, 2 things happen: The original action (making the text bold) and the new action, which causes the button to refresh.

You can now do the same with the other buttons if you wish.

the " and " have to be around the UUID, right?

What I see now is the previously marked button stays for a while, than goes away. I have set time settings to 3 sec

Sorry for the late answer. Yes, the "" go around th UUID.
I dont know what could be the reason why it is not working.

ok, thanks anyway :-))

Is it possible to set the font color based on RGB values with this applescript?

Looking to add light blue instead of dark blue but word does not seem to recognize it. Driving me nuts.

I think it should be possible somehow. Have you checked the AppleScript dictionary of Word? (Find it via Script Editor > File > Open Dictionary...)
As far as I remember I tried to do it too, but didnt manage to get it to work either.

Good suggestion. Couldnt find anything that worked though.

I have tried and tried, but for the life of me cant find the right code. Any other ideas?

not really, sorry