MacOCD wrote:I actually came across an odd bug in the textutil conversion process where on occasion the resulting .doc can't be opened by MS Word via Applescript. I get a message saying the filetype is blocked.
It could be due to textutil converting to doc, which is the very old Word format, and it might not be converting it properly. Try changing the textutil -convert option to docx instead.
MacOCD wrote:I also needed the text to all be Bold to be more readable as I'm actually having to use fontsize 5.5 (instead of size 8 in the sample code above) to fit a page width of my reports on a Landscaped A4 sheet.
Since this is primarily going to be used for PDF viewing on a computer, you are not limited to a physical paper size. Instead of using A4 paper dimensions (8.26"x11.69"), try setting the document dimensions to any size you wish. If you want to stay with defined sizes, try Super A (8.94"x14") or Super B (13"x19"). With a landscaped Super B page, the extra 7" will allow you to increase the font size back to 8 or even perhaps 10!
If you might have to print the reports but want to use a huge custom PDF size, keep the aspect ratio the same as the paper so it will scale down nicely. For example, the A4 ratio is about 0.7 (8.26/11.69=0.7065868263) so when creating a custom [landscape] page size of 30" width, the height should be 21".
Another option is to skip the Word steps and convert the text directly to PDF. There are a few command line utilities to do it out there but some are very complicated. The simplest utility I've found is
text2pdf. He doesn't offer an OSX binary to download so I've downloaded the source and compiled it. You can
download it here.
The help text shows the command options
- Code: Select all
text2pdf [options] [filename]
text2pdf makes a 7-bit clean PDF file (version 1.1) from any input file.
It reads from standard input or a named file, and writes the PDF file
to standard output.
There are various options as follows:
-h show this message
-f<font> use PostScript <font> (must be in standard 14, default: Courier)
-I use ISOLatin1Encoding
-s<size> use font at given pointsize (default 10)
-v<dist> use given line spacing (default 12 points)
-l<lines> lines per page (default 60, determined automatically
if unspecified)
-c<chars> maximum characters per line (default 80)
-t<spaces> spaces per tab character (default 8)
-F ignore formfeed characters (^L)
-A4 use A4 paper (default Letter)
-A3 use A3 paper (default Letter)
-x<width> independent paper width in points
-y<height> independent paper height in points
-2 format in 2 columns
-L landscape mode
For example, to convert report.txt to a PDF with the Super B page landscape dimensions, using Courier New font, size 18, line spacing of 20, and 160 characters per line, the command would be
- Code: Select all
text2pdf -x1368 -y936 -fCourierNewPSMT -s18 -v20 -c160 report.txt > report.pdf
Note that the font name must be the PostScript name, not the human friendly name (Courier New). To get the PostScript name, open the Font Book application, locate the font and style you want and choose the View>Show Font Info menu (or press Cmd+I). The first line in the list should be the PostScript name you need. If you want to stick with Courier New in bold, that would be CourierNewPS-BoldMT
Here are a couple of PDF examples I've created if you would like to see what it can do.
spook5-250.pdfspook6-210.pdfBased on what you specified earlier, these are A4 page sizes in Landscape orientation. When using size 6 font, it could fit 210 characters on each line. Using size 5, it could fit 250 characters. Here are the commands I used to create them.
- Code: Select all
text2pdf -fCourierNewPSMT -L -A4 -c250 -s5 -v5 spook.txt > spook5-250.pdf
text2pdf -fCourierNewPSMT -L -A4 -c210 -s6 -v6 spook.txt > spook6-210.pdf
With a bit of tweaking, I'm sure you can make it work with your reports.
Here is an Applescript you can use within a Hazel action to do the conversion. You will want to have the rule actions move, rename, or flag the text file so that Hazel doesn't keep converting the file over and over.
- Code: Select all
-- Download and save the text2pdf binary into your desired location
-- Change the 2 lines below to where you put the text2pdf binary
-- and any options you wish to pass to it for each conversion
set _text2pdf to "/usr/local/bin/text2pdf"
set _args to "-fCourierNewPSMT -L -A4 -c250 -s5 -v5"
-- If you don't need to pass args, don't delete it! Just set it to ""
-- You should not have to change anything below here
tell application "Finder" to set _parent_dir to (container of (item theFile) as text)
tell application "Finder" to set _theFile_POSIX to POSIX path of theFile
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set _newName to the last text item of (theFile as text)
set AppleScript's text item delimiters to oldDelimiters
if _newName contains "." then
set _newName to (the reverse of every character of _newName) as string
set x to the offset of "." in _newName
set _newName to (text (x + 1) thru -1 of _newName)
set _newName to (the reverse of every character of _newName) as string
end if
tell application "Finder" to set _thePDF_POSIX to POSIX path of (_parent_dir & _newName & ".pdf")
set _shell_cmd to _text2pdf & " " & _args & " " & _theFile_POSIX & " > " & _thePDF_POSIX
try
tell me to do shell script _shell_cmd
on error errText number errNum
return {hazelOutputAttributes:{errNum, errText}}
end try