Apply Styling to Plain Text and Create Rich Text [Example]

This macro is based on Macro by CafeTran_Training. Thanks for a great idea!

MACRO:   Apply Styling to Plain Text and Create Rich Text [Example]

~~~ VER: 1.0    2017-10-09 ~~~

DOWNLOAD:

Apply Styling to Plain Text and Create Rich Text [Example].kmmacros (8.2 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Use Case

  • You need to apply styling to part of a string.
  • The KM Action Apply Style to Clipboard action (KM Wiki) works well if you want to apply the same styling to the entire string (clipboard), but not if you need to apply to parts.
  • I added Font CSS to override the Times 12px that is the default used by textutil

ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Show How to Apply Style to Part of Text

Based on Macro by CafeTran_Training

HOW TO USE

  • Set the plain text in the first Action
  • Set the HTML styling in the 2nd Action.
  • Trigger this macro

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

REQUIRES:

  1. KM 8.0.3+
  • But it can be written in KM 7.3.1+
  • It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
    .
  1. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
      .
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    • ALL Actions that are shown in the magenta color

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.


Shell Script to Convert HTML to Rich Text

Results are put on clipboard.

echo $KMVAR_Local__HTML | textutil -stdin -stdout -format html -convert rtf | pbcopy
1 Like

I’m sorry if this comes across rudely, but that introduction is nearly useless. For a standalone post, linking to the middle of another thread defeats the purpose of having a separate post. I think it’s reasonable to expect a post in the Macro Library forum to include introductory text explaining the ensuing macro. I can understand including a citation to the earlier thread—in fact I’d expect it, as I believe it’s correct to give proper credit—but requiring a visit to the prior thread in order to understand the current one just doesn’t make sense to me.

Did you read the Release Notes???

This is NOT a complicated macro. Just reading the custom names I have given each Action are a huge clue as to what they do. Did you read the Actions???

You might note that at least one other user "liked" the post.

But yes, I find your wording rude.
No doubt I could have provided more details, and maybe it is not up to my usual standards, but I didn't have time to embellish it more. I am NOT being paid to provide this macro, or any other help in this forum. Most people are willing to accept what they are given for FREE with some amount of gratitude.

If you think you can do a better job, then have at it. Feel free to show me up, show me and everyone how much better you can do.

If you have questions, feel free to ask.
If you want to complain about the lacking documentation, ask nicely.
If you really feel compelled to be so rude and critical, then do it in a PM. Let's not bore and sidetrack the other users.

Have a nice day.

1 Like

It is not reasonable to expect someone doing something for others for free to do any more than they are willing to do.

Everyone on this forum is free to do as little or as much as they want in helping others - if they do less than sufficient to enable some people to understand the macro, then no one is worse off than if they had done nothing, which is as much as anyone here is obligated to do.

Feel free to add a comment with more information on the working of the macro (respectfully) if you think that would add value to the topic, or even respectfully ask for clarification if desired.

4 Likes

Just popping in in 2018 to say this is a gem of a little macro and idea! When I started with KM I would have had no idea what this meant, now it is goiing to make one of my most used macros more stable and faster by taking out the manual presses of Cmd + B to bold things!

1 Like

I agree this is a handy idea. Now to put my thinking cap on as to when to use it.

Maybe these will give you some ideas:

@JMichaelTX There's one problem, it seems that <SPAN> will ignore return carriage, at this point, all paragraph will be collected into only one paragraph.

I tried to add "white-space:pre-wrap;" into <SPAN style>, doesn't work. How can I fix it?

All HTML ignores RETURN and LF characters. To break to a new line on the rendered web page, you need to use <BR>.

But when I use "style=white-space:pre-wrap;" in HTML file , it works to have a new line. Any way to solve that out?

<span style="white-space:pre-wrap;">
      This is a book.
      I like it.</span>