How to Paste a horizontal line (<hr>) HTML snippet in Apple Mail?

I’m still getting to know KM, so please forgive a newbie question.

When using Apple Mail, I sometimes like to paste in a horizontal line:

to separate content within a message. Normally I do this by copying the horizontal line from a previous message, then pasting it into a new message.

I want to create a shortcut that will allow me to simply paste the horizontal rule into the message wherever I want. I thought I could make this work using the “insert styled text by pasting” action, but when I pasted the copied element in the action it was blank.

Any ideas to accomplish this?

One way is to put some HTML (automatically converted to RTF by textutil) into the clipboard, and then have it pasted.

This, for example, replaces a sequence of 3 asterisks in Mail with a gray rule. You could adjust the details in the html snippet that gets converted to RTF:

Horizontal rule.kmmacros (2.3 KB)

echo '<hr style="background:#CCCCCC; border:0; height:1px" />' | textutil -format html -convert rtf -inputencoding UTF-8 -stdin -stdout | pbcopy -Prefer rtf

PS probably sensible to add a </p> after the <hr />:

echo '<hr style="background:#CCCCCC; border:0; height:1px" /></p>' | textutil -format html -convert rtf -inputencoding UTF-8 -stdin -stdout | pbcopy -Prefer rtf

Though I wonder whether an <hr /> tag is really the best approach here.

It looks (and thanks to Chris Stone for a heads up here) as though OS X Mail’s rendering system only really responds to the css background-color in that tag. So unless you want a rather thick solid color rule, it may be better for the macro to paste a line of characters (underscore perhaps ?), or use underline formatting.

This gives a red bar - experimenting with the other CSS properties works well in Safari, but less rewardingly in Mail:

echo '<style>.pastedrule{background-color:#CC0000; display: block;height: 1px;margin: 1em 0;border: 0;border-top: 1px solid #e9e9e9;padding: 0;}</style><hr class="pastedrule" /></p>' | textutil -format html -convert rtf -inputencoding UTF-8 -stdin -stdout | pbcopy -Prefer rtf

Excellent. Thanks so much!

Yes, a 1px line would be preferable, but this works just fine for what I need it for.

A simple and robust way to accomplish a visual near-equivalent is to use sequential em-dashes.

The em-dash can be typed using ⌥{dash}.

E.g.: –––––––––––––––––––––––––––––––––

Dashed lines can be typed using an en-dash, ⇧⌥{dash}.

E.g.: ——————————————————

This does not insert HTML. Imho, that’s advantageous.

Otoh, the line is a fixed width.

Using KM (and staying simple), you can either repeat the number of characters to insert, followed by a {return}, or you can save the line+{return} as either a variable or a named clipboard, and insert it whole.

You can get the same result without resorting to KM. Just set up a text substitution at “Preferences ▹ Keyboard ▹ Text”.

I want to do the same thing for Gmail.

Is there a way to accomplish this when in the Gmail web compose window? I want this to span across the entire compose page, so I do not want to simply draw hyphens.

Please pass along any ideas.

You might be able to adapt this macro for your needs:

###Macro: Paste Horizontal Line (Rich Text)

Many thanks for the reply.

I did find that after I sent this message and tried that macro, but it did not work for me - Could be my limitation of course and less a limitation of the technology!.

Can you be more specific?

Here’s the key:

  1. In the app where you want the HL, manually create it.
  • The copy it and paste as a new KM Named Clipboard named “HL Gmail”
  • Add a new Switch Case for “Gmail”
  1. If the app doesn’t support that, then create HTML file with the HL, then follow the instructions in the Comment Action “Setup Instructions – Generic Rich Text Apps”:
Create a HTML file named "Horizontal-Line.html" with this text:


Display this file in Safari (see why below).
Click in the body of the page, and select all (⌘A), then copy (⌘C)
Open the KM Editor Preferences
Click on the "Clipboards" Tab

IF the "Horizontal Line" Clipboard already exists:
  • Click on the name
  • Paste
  • Click on the ➕ button at the bottom to create a new Named Clipboard.
      • This will create the clipboard, AND paste to it using the current System Clipboard
  • Rename this Clipboard "Horizontal Line"

That's it.  You are now ready to use this macro.

Well, to be specific, I did do all those things, including the building of the horizontal line and putting it in KM Clipboards.

The line just never materializes when executing in Gmail.

The application is actually Chrome, since Gmail runs within Chrome.

With the key being that I modify the KM >Preferences>Clipboard> “Horizontal Line” , pasting in it the .html file result displayed in Safari (via Safari, load in, copy with Command A command V).

I also tried copying the horizontal line similarly from a Google Doc (those horizontal lines copy in just fine) and pasting it in the KM Horizontal Line Clipboard and executing it that way.

I don’t need a complex thing right now for multiple applications. Evernote, for example, has a simple button method for inserting a horizontal line. Gmail is my specific issue.

I don't know if either of these will be acceptable to you, but I pasted two different HLs into a GMail compose window. Both of the are actually characters:

1 Like

I have simply made a similar thing with 8 asterisks will:

  1. Draw a line in text consisting of 40 characters
    example: ____________________________________________________________

And then a line feed.

Not quite what I want, but I did say I want to keep it simple.

I believe the solution you propose is similar, with no guarantee to span the entire email. Right?



So I implemented it using “Insert text by typing”. It throws a horizontal line and serves the purpose. So yeah, keeping it simple.

Many thanks for the support.

1 Like