Why does text show differently between Terminal and KM Window?

You can get an ugly unformatted man page by piping it through col, which...

filters out reverse (and half reverse) line feeds so that the output is in the correct order with only forward and half forward line feeds, and replaces white-space characters with tabs where possible.

The -b option tells it to not output any backspaces. So this works:

man pmset | col -b

Displayed in a window, I get this:

However, I honestly don't know if that's good enough, or even what this thread was originally about :). I just know it works.


1 Like

Thank you, both of you, for amazing fixes! These (from what I understand) very different approaches result in identical results, that as far as I can see are identical to what is returned from terminal, of course without the formatting.

The | col -b will be he one I use, as it seems like the most "native" solution, but otherwise I'd be more than confident using the | sed 's/.\x08//g' one. I would not go as far as saying the unformatted text is ugly, it's plain, less attractive, but very readable!

The only thing that could top this solve would be if anyone had any idea on how to display formatted results like this, with the formatting, within a KM window, but as of now this is a very good solution!

I'm pretty sure you could do it by outputting the formatted man page to a PDF file, then opening that PDF file in a custom HTML prompt in Keyboard Maestro. Unfortunately, I don't have the time to play around with it beyond thinking it should work :).

As a start, though, this sample macro will create a PDF of whatever page you pass it, then open it in Preview:

__man to PDF.kmmacros (2.1 KB)

Once you have the PDF, it's just a matter of getting it into a custom HTML prompt window. I know that's possible, but it'd take me a while to figure out how.


1 Like

I think you are definitely on to a way of displaying fully formatted the man pages here. But as I wouldn't even know where to begin understanding how to set this up using HTML, I personally am at a loss here. And I probably then have to settle with the unformatted text returned through your | col -b fix. Which is not at all the worst of compromises

OK, I spent a bit of time on it this morning :).

View PDF of man pages in KM.kmmacros (6.4 KB)

That macro will prompt for the Unix command you wish to see:

And then display it centered onscreen in a window with the dimensions set by the first two variables:



Wow, this is truly impressive! Both how beautiful you've made the data display, but also how intuitive and simple you've made it to type in all kinds of different unix commands for further exploration! I will definitely be using this tool allot when trying to understand and modify all the useful scripts I find here on this forum and other places on the web.

Currently using this tool to make better sense of the pstopdf command you here now introduced me to!

Glad you like it. In theory, the macro should delete the file it made in /tmp, but those files get wiped by the OS on a regular basis anyway. But if you wanted to do the cleanup, just add a Delete File action as the last step:


That is clever. However it shouldn't be too hard to upgrade it to give a list of possible commands instead of making the user type the command in manually. I think you can get KM to generate a list of "mannable" commands using this:

apropos -s 1 .

The number of possible shell commands with man pages is overwhelming: 879.

It'd be easy and yes, overwhelming. :slight_smile:

You could present them in a Prompt With List, but I still think it's a bit too much. That's part of why I just made it "tell me about this command," instead of trying to make it handle everything.

It could also look at the clipboard and compare that to a list of possible commands, then run automatically on that if it found a match. All sorts of stuff is possible; I was mainly interested in getting the PDF into a KM HTML prompt :).


1 Like

Lovely work, Rob (@griffman).

Out of curiosity, prior to using pstopdf, is there a trofftops or some such? I'm wondering if the man source files are still in Troff, and I'm not able download your macro right now.

Why am I asking? Who cares about Troff? I spent many years with Troff, earning my "UNIX Guru" stripes by writing my own Troff macro package to produce the "CommUNIXations" newsletter for /usr/group, now UniForum, while /usr/group was hashing out the Posix standard. Doing the newsletter with Troff was a kind of an "eat our own dogfood" mandate. When one of the UniForum members produced TeX for UNIX, I wrote a sed-based filter system to convert drafts using my Troff macros into TeX where I used TeX's \box-es for page layout and turned the newsletter into a magazine. Lots of fun (and late nights) automating it, which kept an otherwise tedious job interesting.

You can install groff using Homebrew, but troff isn't bundled on macOS. pstopdf is standard, so the command should work on anyone's Mac.


So the man source files are saved in PostScript?

I'll look at your macro when I'm on my computer and have access to the files.

Actually, now I'm confused :slight_smile: ... man -t sends the command through troff, but as far as I can tell, troff doesn't exist. (I am not a shell command wizard once I get past the basics.)

So it seems troff is there. The Unix command in the macro is just this:

man -t "$KMVAR_local__Command" | pstopdf -i -o /tmp/"$KMVAR_instancetheFile"

The first part sends the man page to troff, then pstopdf converts it to a PDF.


Thanks. Got it. I have no idea about the -t option. I misunderstood your collapsed Action title, "Make it into a filename", as generating the filename of the man source. Nope. The man command does not work that way. If I can find where MacOS keeps the man source, that will answer part of my questions. Maybe folks on Ask Different can explain the practical meaning of the -t.

If you just do this:

man -t pmset > /tmp/pmset.ps

You'll find the PostScript version of the pmset command in the /tmp folder.


I did:

man man

and that included this info about -t:

-t     Use /usr/bin/groff -Tps -mandoc -c to format  the  manual  page,
       passing  the  output  to  stdout.   The default output format of
       /usr/bin/groff -Tps -mandoc -c is Postscript, refer to the  man-
       ual  page  of /usr/bin/groff -Tps -mandoc -c for ways to pick an
       alternate format.

So -t automatically runs groff and outputs in PostScript format.

That page also described where the MANPATH environment variable is set (under /priviate) and I succeeded in finding that pmset source is in /usr/share/man/man1/pmset.1.

Here's a fragment of the beginning of that file:

( expand / collapse )
.\" Copyright (c) 2002-2012 Apple Computer, Inc.  All rights reserved.
.Dd November 9, 2012
.Os Darwin
.Nm pmset
.Nd manipulate power management settings
.Op Fl a | b | c | u
.Op Ar setting Ar value
.Op ...
.Fl u
.Op haltlevel Ar percent
.Op haltafter Ar minutes
.Op haltremain Ar minutes
.Fl g
.Op Ar option
.Op cancel | cancelall
type date+time
.Op owner
repeat cancel
repeat type weekdays time
.Op wake | poweron
.Op touch | sleepnow | displaysleepnow | boot
.\.Op Fl a b c u
.\.Op dim
.\.Op spindown
.\.Op sleep
.\.Op womp
.\.Op ring
.\.Op autorestart
.\.Op acwake
manages power management settings such as idle sleep timing, wake on administrative access, automatic restart on power loss, etc.
Note that processes may dynamically override these power management settings by using
I/O Kit power assertions.
Whenever processes override any system power settings,
will list those processes and their power assertions in
.Fl g
.Fl g 
assertions. See 
.Xr caffeinate 8 .
can modify the values of any of the power management settings defined below. You may specify one or more setting & value pairs on the command-line invocation of pmset.
.Fl a,
.Fl b,
.Fl c,
.Fl u
flags determine whether the settings apply to battery (
.Fl b
charger (wall power) (
.Fl c
), UPS (
.Fl u
) or all (
.Fl a
Use a minutes argument of 0 to set the idle time to never for
.Ar sleep
.Ar disksleep
.Ar displaysleep
must be run as root in order to modify any settings.