Is it possible to search the clipboard and style text between specific characters

I have a script that copies text from a txt file on my desktop to the clipboard and pastes it to an email. In that text are some headers that are plain text surrounded by asterisks like this *Header title*. Is it possible to search that clipboard and format just those headers bold?

Hey David,

No, you can’t do that with Keyboard Maestro actions.

Applying style to the clipboard doesn’t include a bold option.

That said – it can be done.

Search for “convert rtf” and/or “textutil” on the forum.

If you know a little HTML and CSS you can get pretty fancy.

A simple example:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">     
    <head>      
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />   
        <title>Hi, I'm bold!</title>  
        <style type="text/css">
            p {
              font-weight:bold;
              font-size:26px;
            }
        </style>
    </head>   
    <body>
        <p>Hi, I'm very bold and HUGE!</p>
        Line One<br>
        Line Two<br>
        Line Three<br>
    </body>
</html>

If your file is already in the clipboard as HTML code, you can run this shell script from an Execute a Shell Script action:

pbpaste | textutil -convert rtf -stdin -stdout | pbcopy

You can also read it directly from the file or from a Keyboard Maestro variable.

-Chris