I print almost everything to file into a print queue directory
($HOME/pq). I name the files 01, 02, ..., 99 (so they stay in the order
printed) and then run them through my duplex printing emulator (duplexpr
on sourceforge).
I also have a bash script that looks at $HOME/pq and figures out what
the next file name (number) will be and stores it in a bash variable
(NEXT). Currently, it displays it in a pop-up (zenity - and its text
can't be selected) so I can see it in the gui without going to a
console. I then just retype it into the print dialog.
What I'd like to do is add something at the end of the following script
that, expressed as pseudocode would be:
keyboard.send_keys("<value from NEXT><enter>")
This would be the "sliced bread" of printing for me. I could just type
ctrl-p (my hotkey), and everything else would be automatic. I wouldn't
have to keep looking at my print queue to see what the next available
number is, etc..
I'm pretty good at bash, but haven't had time to learn much python yet.
If I knew enough python, I could probably just rewrite the bash script
in python on the end of the current AK script, but it's more than a few
lines of code (around 40 lines, comment-stripped) and I'm pretty sure
it's well beyond my python coding skills at the moment.
Any ideas on how to glue the two scripts together, etc. would be
appreciated.
TIA
Joe - autokey 0.80.3 - kubuntu lucid Linux x86
# print2file
import time
keyboard.send_keys("<alt>+f")
time.sleep(1.0)
keyboard.send_keys("p")
time.sleep(1.0)
keyboard.send_keys("<tab><home>")
time.sleep(1.0)
keyboard.send_keys("<tab>pq/")
I wasn't clear on environment variables because I read something about
python getting a copy of them that remained static after python started
(wouldn't see updated values) and because I wasn't sure whether setting
a variable in a script (and exporting it) would work if the script was a
child process of python. I think exports only work going into
sub-processes, not coming back out. That's an area I'm fuzzy on.
Anyway, I found great stuff at
http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess
which almost worked and I found the fix for that at
http://stackoverflow.com/questions/4814970/subprocess-check-output-doesnt-seem-to-exist-python-2-6-5
and the working script is now:
# print2file
import time
import subprocess
## Open the File menu
## (can't use <ctrl>+p because that's the hotkey)
keyboard.send_keys("<alt>+f")
time.sleep(1.0)
## Select Print
keyboard.send_keys("p")
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(1.0)
## tab to the file name field and enter the print queue directory path
keyboard.send_keys("<tab>pq/")
## Call my bash script to get the next print file name (from stdout)
##output = subprocess.check_output(['pqnext_py']) ##won't work until
python 2.7
output = subprocess.Popen(['pqnext_py'],
stdout=subprocess.PIPE).communicate()[0]
## add the file name to the path and then press enter to complete the
dialog
keyboard.send_keys(output)
keyboard.send_keys("<enter>")
Now, I just have to read some more so I can add a bit of code to handle
the case if my bash script returns an error.
Also, I may take the last <enter> out so it's not quite so automagical.
Thanks again.
Joe