-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextras.txt
207 lines (170 loc) · 6.29 KB
/
extras.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Here are some "as is" extras for use with duplexpr.
Last modified: 03/04/2017
Be sure to check names of commands, etc. to make avoid conflicts with anything else you may already have installed on your system.
For these first few to work you need to add something like
export PQ="the full path to your print queue"
to $HOME/.bashrc
This is also useful when you need to put anything into the print queue from the command line.
You can just say things like
cp some_file $PQ
without having to retype the full path.
Aliases for printing:
(add to ~/.bash_aliases or ~/.bashrc)
alias pqb='kmprbatches -1' ## show how printing will be broken into batches
alias pql='cd "${PQ}";[ -n "$(ls)" ] && mprb -i * || echo "Print Queue Empty"' ## list the print queue
alias pqp='cd "${PQ}";[ -n "$(ls)" ] && mprb * || echo "Print Queue Empty"' ## print the jobs in the print queue
----
Here's a function which can be added to .bashrc .
When you type pq, it will change into your print queue and list the files there.
pq() {
cd "${PQ}"
echo -en "\t\t"
pwd
ls
echo
}
----
AutoKey macro for printing to the print queue from Firefox or Thunderbird.
Set a filter so this only runs if the window title includes mozilla or Thunderbird:
.*Thunderbird.*|.*Mozilla.*
Assign Super+P as the hotkey.
[code]
##print2file
## Copyleft 2012/08/31 - Joseph J. Pollock JPmicrosystems GPL
## Last Modified 2018/02/28 - Handle new Mozilla print dialog
## Handle printing please wait
##
## May need modifications to work with Python 3.x
##
## Assign <Super>+p for Firefox and Thunderbird
## to print to file in a special print queue using
## numbered file names, 01, 02, ... so the print jobs stay in order
##
## The new file name/number will have the same number of digits as the highest
## existing file name/number with left zero padding
## Two digit file names/numbers is the default.
##
## You can "seed" the process using e.g. touch 0000 in an empty print queue
## Intended for use with duplexpr
## http://sourceforge.net/projects/duplexpr/
##
## User must manually create print queue directory (~/pq)
##
## Not sure about the following still being necessary, but it works
## Set all *.print_to_filename variables in prefs.js (about:config)
## to path to print queue/01.ps (or .pdf)
## e.g. /home/shelelia/pq/01.ps (or .pdf)
##
## Using Ctrl+P as the hotkey doesn't seem to work in Firefox any more
## Hotkey <Super>+p
## Window Filter .*Thunderbird.*|.*Mozilla.*
##
## Changes <Super>+p to
## Print to file and looks at the print queue (~/pq) - hard coded
## Finds the last print file number and increments it by one
## Also handles files ending in ".pdf" or ".ps"
## Doesn't send final <Enter> so additional options like Print Selection
## can be set by the user
import os
import re
import string
import time
def filenum ():
## Gets next file number
## Set path to print queue
path = os.getenv("HOME") + '/pq' ## Change this if your print queue is elsewhere
## Get all the files in the print queue in a list
## Handle filesystem error
try:
dirlist=os.listdir(path)
except:
return "EE"
## And sort it in reverse order
## So the largest numbered file is first
dirlist.sort(reverse=True)
## If there aren't any files then
## Set last file to 0
## else, set it to the last file with a valid number
## Defend script against non-numeric file names
## go down the reverse sorted list until a numeric one is found
fn=""
digits = 2 ## default to 2-digit file numbers
files = len(dirlist)
if files > 0:
i = 0
##print("Found [" + str(files) + "] files") ## debug
while (i < files) and (fn == ""):
name = dirlist[i]
##print("name [" + name + "]") ## debug
## regex for case insensitive replace of the last occurrence
## of .pdf or .ps at the end of the string with nothing
## if the file name has more than one, it's not one of ours
name = re.sub(r'\.(?i)(pdf|ps)?$', "", name)
## Use the length of the one we found to set the zero padding length
if name.isdigit():
fn = str(int(name) + 1)
digits = len(name)
i += 1
## If no numeric file names were found
if fn == "":
fn="1"
##print("fn [" + fn + "]")
## left zero fill the file name to the same length as the one we found
##print("fn [" + fn + "] digits [" + str(digits) + "]") ## debug
fn = fn.zfill(digits)
return fn
### DEBUG
## This code is for standalone testing outside of AutoKey
##output = filenum()
##print("Next File Number is [" + output + "]")
##quit()
### DEBUG
## Open the File menu
## Only works if Main Menu bar is displayed
## If we're not using Ctrl+p for the hotkey any more,
## maybe we can use it instead of AlT+f,p
##keyboard.send_keys("<alt>+f")
##time.sleep(1.0)
#### Select Print
##keyboard.send_keys("p")
##time.sleep(1.0)
keyboard.send_keys("<ctrl>+p")
time.sleep(1.0)
winTitle = window.get_active_title()
while (winTitle == "Printing"):
time.sleep(1.0)
winTitle = window.get_active_title()
## error window processing - for when FF complains about
## not being able to print all elements of the page
winTitle = window.get_active_title()
winClass = window.get_active_class()
if winTitle == "Printer Error" and winClass == "Dialog.Firefox":
keyboard.send_keys("<enter>")
time.sleep(1.0)
if winTitle == "Print Preview Error" and winClass == "Dialog.Firefox":
keyboard.send_keys("<enter>")
time.sleep(1.0)
if winClass == "Dialog.Firefox":
keyboard.send_keys("<enter>")
time.sleep(1.0)
## tab to the printer selection list, then to the top of the list
## which is the Print to File selection
keyboard.send_keys("<tab><home>")
time.sleep(2.0)
## tab to the file name field and enter the print queue directory path
keyboard.send_keys("<tab>")
output = filenum()
keyboard.send_keys("<enter>")
time.sleep(1.0)
## complete the file name field in the select file dialog
keyboard.send_keys(output)
keyboard.send_keys("<enter>")
time.sleep(1.0)
## Tab away from the File select button so the user can just press Enter
## But don't send an enter so the user can select
## other options before printing
keyboard.send_keys("<tab>")
time.sleep(0.5)
keyboard.send_keys("<tab>")
[/code]
----