Text Expansion: System & Hardware Info

Sure.

Highly useful! Thanks.

To expand @ccstone’s contribution to format as a table, here is how you can specify a mono-spaced font for pasting into other applications. @Tom, this might help with the email showing in a proportional-spaced font, but it actually depends on the email program.

Append the following code to the end of Chris’ command. It will take the columnized output, convert into Rich Text Format with your desired font, then puts it onto the clipboard.

| textutil -convert rtf -font 'Courier New' -stdin -stdout | pbcopy

By default it will be in font size 12. If you want a different size, add the -fontsize argument and your desired size. For example,

| textutil -convert rtf -font 'Courier New' -fontsize 18 -stdin -stdout | pbcopy

Hope this helps.

5 Likes

Well done Onan!   :smile:

-Chris

2 Likes

I tested this, and also the KM-native RTFing action, but it doesn’t work if you have plain text fields (for example a new Mail message set to plain text, or any document in BBedit, etc.)

This means that you have to have two macros, one for plain, one for rich text. (Or a “if then” clause).

So, while these table-styling approaches are very nice, they are not robust at all. I still think that the vanilla approach is the most convenient.

Hey Tom,

Sure enough. I'm shocked the RTF emplaced on the clipboard with pbcopy won't paste as plain text where appropriate. That's very un-Mac-like.

I'm fairly sure it's possible to put more than 1 text flavor on the clipboard using ASObjC, but I don't have time to look into it at the moment.

On the other hand there's an easy fix using Keyboard Maestro:
(Retains format for both Plain Text and Rich Text documents)

System Information v1.02.kmmacros (4.1 KB)

This macro emplaces text appropriately in every venue tested so far.

-Chris

[ EDITED 2016/04/22 14:33 CST – minor improvements to macro ]

3 Likes

Chris, thanks for sharing.
So, to make sure I understand, your macro puts BOTH plain text and rich text on the Clipboard, right?

Yes. Give it a try.  :smile:

-Chris

The pasteboard will send the contents back in whatever format the application is asking for, if it is supported (ie you can't paste an image into a plain text document)

[quote="ccstone, post:13, topic:3337"]I'm shocked the RTF won't paste as plain text where appropriate
[/quote]

When it wasn't working for you, did you get the raw RTF code? If so, that is bad. It could mean the pboard service has failed. A reboot is usually required. Here is a good write-up of the issue.

After sending to the pasteboard, switch to the Finder and select Edit>Show Clipboard. It should show formatted text and at the bottom it should say the contents are RTF.

I tested both versions and the text was on the clipboard as RTF. Here are some quick results.

  • In TextEdit with a Rich Text document, it pasted as formatted RTF text. :thumbsup:
  • In BBEdit, it pasted as plain text. :thumbsup:
  • In Chrome, composing an email message in Gmail, it pasted wrong. It was Sans Serif text and padding added between each line, as if they were paragraphs. :thumbsdown:
  • If I ran cat file.rtf | pbcopy, I had mixed results. Sometimes it would paste RTF but other times it would not paste anything and then the Paste option stopped working as if the clipboard was empty or contained something it couldn't accept, but only for that app until I quit/restarted it. :thinking:

tl;dr:
After more testing and research, I've determined that the pbcopy/pbpaste utilities are flaky and probably shouldn't be used if possible. I would recommend removing the | pbcopy from the script and have KM save it directly to the clipboard.

2 Likes

Hey Onan,

No.

If you run this:

echo "Nuts!" | pbcopy; sleep 0.25;
system_profiler SPHardwareDataType SPDisplaysDataType SPSoftwareDataType | grep -E "Model|Version|Processor|Cores|Memory: \d|VRAM|Integrity|Time" | sed -E 's!^ *!!; s!([^0-9]): !\1•:•!' | column -t -s'•' | textutil -convert rtf -font 'Menlo' -fontsize 14 -stdin -stdout | pbcopy;

“Nuts!” will paste into BBEdit, but the full sysinfo text will paste into TextEdit.

So, something is odd indeed...

You're right – pbcopy isn't needed in my macro above. I'll fix that shortly.

-Chris

Thanks, Chris. I had tried this before, too (that’s what i meant with “KM-native RTFing action”) and now I literally spent half an hour to find out why yours is working while mine is not. And the thing was…

…I’ve simply forgot to append the paste action :face_with_head_bandage::astonished:

2 posts were split to a new topic: Paste System Info (min, med, or max)

Hey Tom,

PEBKAC is always annoying.

One of my repeat offenders is forgetting to turn on regular expressions in a search/replace action.

-Chris

2 Likes

Different strokes for different folks. The beauty is we can choose what ever we want with Keyboard Maestro

So I have a question for anyone who cares to comment. I have been using ";;" at the end of triggers. e.g. "km;;" expands to "Keyboard Maestro".

I note both @Tom and @JMichaelTX used ";" at the beginning of their trigger. What are the dangers of using either ";;" or ";" as part of the trigger, since some languages use semi-colons to separate values or end arguments?

Great thread everyone! How do I miss these? This one was way back on the calendar.

The thing with “;” at end is that the combination of letters followed by a “;” is very common in normal text, whereas the combination of a “;” followed by letters is not common (usually there is a space in-between).

But I don’t see why you shouldn’t use “;;” at the end of the abbreviation. I have quite some abbreviations with two Space characters at the end, which is similarly easy to type as “;;”.

Alternatively you can also surround the abbreviation with the special chars, for example “;er;”, if you would have conflicts otherwise.

1 Like

I have been using ";" at the beginning of all of my text expansion (TE) triggers for years now, in KM and other tools. So far, I've not had a false firing. As @Tom says, the semicolon is rarely, if ever, followed by non-white space character, at least in the English language.

My standard naming convention for text expansion is:
;<category abbreviation>.<text mnemonic><SPACE>

for example: ";km.as " -- insert an AppleScript code block in Keyboard Maestro

I find the semicolon very easy to type (as a touch typist), so this works well for me.
The semicolon works well to denote the start of a TE, and a SPACE works well to denote the end of a TE.

I have chosen good mnemonics for my <category abbreviation>, like:

  • km -- Keyboard Maestro
  • as -- AppleScript
  • js -- JavaScript
  • jxa -- JavaScript for Automation (JXA)
  • en -- Evernote
  • etc.

Use of a <category abbreviation> will allow you to quickly search for all TEs with that abbreviation when using tools like Typinator and Text Expander. Unfortunately, I don't know of a way to do this search in KM. Anyone?

The key, of course, is to choose characters that work well for you in the language you use, and that are intuitive to you. Some of this may be learned behavior, like using the semicolon. It is now a muscle memory for me. :wink:

2 Likes

@JMichaelTX - good system. Makes sense to me and is the most logical choice. More and more I am starting to use name.name or name.name.name conventions in Filemaker Pro as a way to organize layout, button, text object calls from scripts.

I wonder if there should be a Keyboard Maestro Standards page similar to http://filemakerstandards.org/display/cs/Overview or would that be overkill?

@Tom, I like the technique to perform different actions based on uppercase/lowercase letters in a triggering word. Must remember that.

2 Likes

Someone please, please, explain to me how to install this macro?

It is really quite easy:

  1. click on the link to download the macro to your Mac
  1. When the download completes, double-click on the file (.kmmacros) to import into your KM Editor app.
  2. The KM Editor should open to the Macro Group and Macro that was just imported.
  3. Review the Macro Triggers, and adjust as needed.
  4. When you are ready to use, make sure the macro is enabled.

Questions?

1 Like