Importing PDF version of man page (to preserve highlighting)

The bundled import man page script is very useful, but by importing the pages as text, it does drop keyword (and header) highlighting.

I personally find that speed of visual scanning and comprehension is helped by the highlighting, so I am using a lightly edited version of the script, which imports man pages as PDF files.

-- Man Page
-- Created by Christian Grunenberg on Sat Apr 16 2005.
-- Copyright (c) 2005-2009. All rights reserved.

-- Edited by Houthakker 2011 Feb 12 to import PDF (rather than text) version of man page
-- (to preserve highlighting of keywords and headers)

tell application id "com.devon-technologies.thinkpro2"
			set page to display name editor "Man page" info "Enter the man page to import:"
			if page is not "" then exit repeat
		end repeat
		show progress indicator "Converting man page to PDF ..." steps -1
		set strPDF to "~/" & page & ".pdf"
		set strCmd to "man -t " & (quoted form of page) & " | pstopdf -i -o " & strPDF
		do shell script strCmd
		tell application id ""
			set strTmpPath to (((path to home folder) as text) & page & ".pdf")
			set blnExists to exists strTmpPath
		end tell
		if blnExists then
			set oRec to import strPDF name page to current group type pdf and postscript
			tell application id "" to delete file strTmpPath
			error "Page does not exist."
		end if
		hide progress indicator
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
		hide progress indicator
	end try
end tell

Thanks for this useful revision! We could replace the bundled script with this one in case that you’re interested. Please let me know, thanks.

Yes, of course, you would be very welcome to do that.

(I’ve added a progress indicator to avoid confusion, as converting to PDF can sometimes take a few seconds).

Thanks a lot! I’ll add this to the upcoming version 2.0.8.