Changing the font where the cursor is

Well, I guess that makes the rest of us idiots too! :rofl: I, perhaps, remain one, since I am still not totally in the picture here…

Favourites where? We still don’t know which application you are using, do we?

I finally managed to work out how to ā€œfavouriteā€[1] styles in TextEdit (I hadn’t used them before, and Apple’s interface decisions are as clunky as one would expect) but I think you must be using a different application—one that makes favourite styles available via a menu, and therefore, accessible via a shortcut defined under System Settings, in the way that you explained.

Edit: I now see that the dropdown list withing TextEdit’s styles box shows that the shortcut has been assigned! It’s just that (on my system at least) they don’t work. :rofl: I’m going back to plain text, and you should probably ignore this reply…

If my thinking there is correct, then the menu would also be available via a Select or show a menu item action in KM, too, wouldn’t it? If so, there would be the option of assigning a key shortcut via KM instead of under System Settings.

Edit: I guess System Settings > Keyboard has its own method of accessing favourite styles.

(Under MacOS 15.7 (Sequoia), that translates as Keyboard > Keyboard shortcuts > App Shortcuts).

No personal criticism was intended; I was just giving my perspective. :wink:


  1. That’s ā€œfavouriteā€ or ā€œfavoriteā€, depending on one’s dialect of English. ā†©ļøŽ

1 Like

I think any app that works with macOS's RTF system. But I'm not sure. Let's take TextEdit, for example.

Under ā€œStile einblendenā€ /I don't know what this is called in English) you can add a style, save it as a favorite, and then assign a shortcut to it. You can also see this shortcut in the menu.

1 Like

Yes, it’s there, as ā€œShow Stylesā€¦ā€, although I took the route via the menu, Format > Font > Styles.

That's strange :thinking:

I think that this is very limited compared to your original solution -- maybe even to TextEdit (or whatever app you do this in) only, in which case you're back to

A style created in TextEdit doesn't seem to be available in Notes or Pages, for example.

So not an idiot -- you were anticipating future problems and creating a more versatile solution :wink:

Haha, thanks, @Nige_S , that’s kind of you, and you’re right. These styles aren’t available in all apps. Whereas my solution probably works in any RTF text field.

But styles have at least one advantage: the corresponding shortcut is applied to selected text, if any is selected. If no text is selected, the new style starts where the cursor is.

I could simply choose two different shortcuts for two different macros. But of course, it would be better to solve this with an if-condition, if possible.

So, if text is selected, apply the new style there; if not, apply the new style where the cursor is.

I found a few scripts on the forum that work with selected text, but I have no idea how to use them in this context.

Can anyone help? Thank you very much!

This works...read the macro name...

Sample Macro- ⌘A For Secleted Text, ⌘B on future text.kmmacros (29.6 KB)

1 Like

A visionary!

I’ll mention this trick just in case it triggers any ideas… I doubt it will help but again it depends on the quirks of the software that you want to use.

I recently wrote a macro based on the Filter system clipboard with smart quotes action. The macro converts the quotation marks of selected text, if there is any, or else on the contents of the clipboard. It uses the copy action and then checking whether the clipboard matches \w+. This works for my use case because the various plain text editors that I use add an empty string to the clipboard if a copy operation is carried out when no text has been selected; only if text has been selected, will the match succeed.

With TextEdit, that trick doesn’t work, because the application doesn’t add anything to the clipboard if no text has been selected before an attempted copy. Perhaps some sort of hack like this might be possible when using other rich text editors..?

1 Like

Thanks a lot, @Joel . It is one macro, but it uses two different shortcuts. Does that mean you don't see a way to do this with the same shortcut?

Yes, by accident. I was trying to cure cancer and discovered penicillin :joy: . As for the rest, I'll have to take a closer look at it. Thanks a lot.

1 Like

But TextEdit is sensible, and doesn't enable the "Copy" menu item if nothing is selected.

So maybe something like (pseudo code):

if the Copy menu item is not enabled
   set Local_noSelection to "1"
   add, select, and copy character
else
   do Copy
   if System Clipboard does not contain rich text
      exit macro -- it might have been a graphic or similar that was copied
   else
      -- do nothing
   end if
end if
format the Clipboard contents
Paste, replacing current selection
if Local_noSelection
   Delete
else
   do nothing -- we've pasted over previously-selected text, so don't delete!
end if

That's off the top of my head, so please please test thoroughly!

As the approach involves sending items to the clipboard, the easiest way is to count the length of the clipboard item.

The problem is that you need to stick something in the clipboard which in the case of "following text" would mean actually selecting empty space and sending it, which to me is worse! This is the point of @Nige_s previous post.

While others may see a way, I do not. Sorry!!

You don't need to be sorry. On the contrary, thank you very much for your interest in my ā€œproblems.ā€ :slightly_smiling_face:

The idea with the menu is great. KM even has a predefined option/condition for that.

That would mean: if ā€œcopyā€ is selectable (in which case text is selected), then apply the new style to that text.

If ā€œcopyā€ isn’t selectable (in which case no text is selected), then change the style starting from where the cursor is.

Did I understand that correctly? let’s see if I can set that up :thinking:

Yes, that will work!

Great idea!!

And here you go...

Sample Macro- ⌘A For Secleted Text.kmmacros (29.2 KB)

Wonderful, thank you so much. Then I, the dummy, won't have to do it myself. :slight_smile:

Just one more question: The macro is supposed to be global. But unfortunately, I use apps in different languages. Instead of ā€œcopy,ā€ it might say ā€œEinsetzen.ā€ Is there a way to work around that?

No -- the point was that most apps are sensible and only enable the Copy menu item when something is selected, so you can use that as a proxy for "is there a selection?".

Sometimes the thing that's selected won't be text, which is why we want to Copy, check, and abort if it isn't.

The main reason the logic in your macro is different to my outline is that I was trying to only put in one "Apply Style" Action, so there's only one place to set our (easily fat-fingered) format settings.

1 Like

Easy, change the "all of the following are true" to "any of the following are true" and add other languages. If you have problems let me know, I will do it for you.

You can check multiple names at once (without adding multiple Conditions!) by using the usual | to mean OR:

1 Like

Agreed, MUCH MUCH better than mine!!

Thanks, @Nige_S and thanks @Joel

The macro works exactly as intended … in every app I've tested it. :smiley:

Am I the only one who needs something like this? I don't think so. For people who write a lot and often switch styles, this is a huge help. Since it's your macro, @Joel could you please add it to the KM library? Sometimes people don't realize what they need until they see it.

Thanks again!