macosmanpage

´Opening local text files like they were x-man-page:// URLs


MacOS has a set of defined URLs for manpages under x-man-page://command.

You can open these from a web browser or directly from Terminal with the command open x-man-page://command, which opens a nice yellow background reader. I am trying to find out what this is, and how I can open other documents in it (like local text files for example).

Under Terminal > Preferences > Profiles you can see there is a Man Page profile, and you can launch a new Terminal window with this profile, so I would assume it is just a Terminal window that the text is written to and then left open (especially as it says [PROCESS COMPLETED] at the bottom of the page).

How would I open a new Terminal window with a specific profile, print text to it and leave it open in the same way?

For example, doing the same to open a .txt in Preview (I am on Catalina so this still works) I can use groff -man -Tps filename.txt | open -f -a Preview. I use this with extracted python help() pages for example. But I would prefer if I could open this in the yellow Terminal reader or window instead of Preview instead.

Edit:

Using the AppleScript provided by @Philippe this function can open most text files in this "reader" view:

function reader {
  if [[ "$1" = /* ]]; then
    osascript ~/Code/scripts/xman_window.scpt "cat $1"
  elif [[ "$1" = ~/* ]]; then
    osascript ~/Code/scripts/xman_window.scpt "cat ${1/#\~/$HOME}"
  else
    osascript ~/Code/scripts/xman_window.scpt "cat $(pwd)/$1"
  fi
}

Solution

  • You can use Applescript, save following script to test.scpt:

    on run {command}
    tell application "Terminal" 
        do script "clear;printf '\\e[3J'; " & command & "; kill -9 $$"
        set current settings of front window to settings set "Man page"
        delay 1
        tell application "System Events" to keystroke (ASCII character 30) using {command down}
    end tell
    end run 
    

    run it with :

    osascript test.scpt "man -P cat ls"