Hello. It should be possible to create a simple cross-platform print option, but I need a little assistance with Apple/Linux, etc…
In Windows I have to first share the printer, and note it’s name, and the computer name. Then I can issue the commands:
os.system('net use lpt1 \\\\ANDYCOMPAQ\\PrimoPDF /persistent:yes')
os.system('type system_ex.txt > LPT1')
Can someone advise me of equivalent commands in other Oses? *
I’m hoping that I can just save the file to print (temporarily) with an ‘.txt’ extension. Otherwise I’ll have to investigate sending the *lines *of the file to the printer.
The output would be completely unformatted and there would be no preview option. As mentioned, it would just be a rough and ready print option. It would, however, be possible to just print the selection and perhaps to give an (approximate) page number or range.
[code]import sublime, sublime_plugin
import os
DEF_COMPUTER = sublime.load_settings(PACKAGE_SETTINGS).get(“comp_name”, \
False)
if not DEF_COMPUTER:
DEF_COMPUTER = os.environ’COMPUTERNAME’]
DEF_PRINTER = sublime.load_settings(PACKAGE_SETTINGS).get(“default_printer”, \
“PrimoPDF”)
Advanced, Print Processor… Text (from RAW) for PrimoPDF
DEF_COMPUTER = “ANDYCOMPAQ”
DEF_PRINTER = “PrimoPDF”
try:
init_printer = “net use lpt1 \\” + DEF_COMPUTER + “\” + DEF_PRINTER +
" /persistent:yes"
os.system(init_printer)
init_printer = True
except Exception:
sublime.status_message(‘Printer not configured correctly.’)
init_printer = False
class PrintDefault(sublime_plugin.WindowCommand):
def run(self):
if init_printer:
vw = self.window.active_view()
vw_str = vw.file_name()
#os.system(‘type system_ex.txt > LPT1’)
os.system(“type " + vw_str.replace(’\’, ‘\\’) + " > LPT1”)
else:
sublime.status_message(‘Printer not configured correctly.’)
[/code]
Actually, print-preview would be kind-of possible using another view, but it wouldn’t look anything like the printed (white) version.
Any advice, or suggestions, are welcome. Andy.
*