Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #92852 > unrolled thread
| Started by | Naftali <nmichalowsky@gmail.com> |
|---|---|
| First post | 2015-06-18 14:04 -0700 |
| Last post | 2015-06-23 21:20 +0100 |
| Articles | 11 — 5 participants |
Back to article view | Back to comp.lang.python
Python File as the Default PDF handler for Windows Naftali <nmichalowsky@gmail.com> - 2015-06-18 14:04 -0700
Re: Python File as the Default PDF handler for Windows Chris Angelico <rosuav@gmail.com> - 2015-06-19 09:46 +1000
Re: Python File as the Default PDF handler for Windows Naftali <nmichalowsky@gmail.com> - 2015-06-18 18:03 -0700
Re: Python File as the Default PDF handler for Windows Chris Angelico <rosuav@gmail.com> - 2015-06-19 11:18 +1000
Re: Python File as the Default PDF handler for Windows MRAB <python@mrabarnett.plus.com> - 2015-06-19 02:39 +0100
Re: Python File as the Default PDF handler for Windows Chris Angelico <rosuav@gmail.com> - 2015-06-19 11:46 +1000
Re: Python File as the Default PDF handler for Windows Naftali <nmichalowsky@gmail.com> - 2015-06-18 18:22 -0700
Re: Python File as the Default PDF handler for Windows Naftali <nmichalowsky@gmail.com> - 2015-06-23 06:39 -0700
Re: Python File as the Default PDF handler for Windows Chris Angelico <rosuav@gmail.com> - 2015-06-24 01:00 +1000
Re: Python File as the Default PDF handler for Windows Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-23 16:12 -0400
Re: Python File as the Default PDF handler for Windows Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-23 21:20 +0100
| From | Naftali <nmichalowsky@gmail.com> |
|---|---|
| Date | 2015-06-18 14:04 -0700 |
| Subject | Python File as the Default PDF handler for Windows |
| Message-ID | <60c5531e-b4b4-43b2-a3b9-0b53e1490dee@googlegroups.com> |
Long time lurker. I'm looking to register a python script as the default pdf reader for windows. I assume I can just register the .py in the section windows section for registering default handlers, but I'm wondering how to access the file from within the program. The issue is this: We have Java application that outputs user uploaded pdf files. It does this simply by instructing windows to open the downloaded pdf file and windows takes it from there. The data entry person will view the pdf and usually upload it into another part of the system. Problem is the second leg of the system modifies the pdf, and thus crashes when the pdf is protected against writing. Data entry make use of a program to unlock them as needed but it is an extra step and it only comes to their awareness after their client crashes on the locked pdf (because it doesn't make sense to check them proactively. I cannot change the Java system. What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like). I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-06-19 09:46 +1000 |
| Message-ID | <mailman.619.1434671173.13271.python-list@python.org> |
| In reply to | #92852 |
On Fri, Jun 19, 2015 at 7:04 AM, Naftali <nmichalowsky@gmail.com> wrote: > What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like). > > I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS. > Possibly the reason you've found nothing is that this isn't actually a Python issue :) What you want to do is tell your OS that when you double-click on a PDF, it should run this program. That's better referred to as "file associations". Different versions of Windows put that in different places, but poke around in your GUI or on the internet and you should be able to find something on updating associations. If you're having trouble getting a Python program to run in that situation, it may help to explicitly name a Python interpreter - an executable binary. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Naftali <nmichalowsky@gmail.com> |
|---|---|
| Date | 2015-06-18 18:03 -0700 |
| Message-ID | <e97c8320-1085-46e1-b004-3b90e30d2e0b@googlegroups.com> |
| In reply to | #92852 |
On Thursday, June 18, 2015 at 5:05:15 PM UTC-4, Naftali wrote: > Long time lurker. > > I'm looking to register a python script as the default pdf reader for windows. I assume I can just register the .py in the section windows section for registering default handlers, but I'm wondering how to access the file from within the program. > > The issue is this: > > We have Java application that outputs user uploaded pdf files. It does this simply by instructing windows to open the downloaded pdf file and windows takes it from there. The data entry person will view the pdf and usually upload it into another part of the system. Problem is the second leg of the system modifies the pdf, and thus crashes when the pdf is protected against writing. Data entry make use of a program to unlock them as needed but it is an extra step and it only comes to their awareness after their client crashes on the locked pdf (because it doesn't make sense to check them proactively. > > I cannot change the Java system. > > What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like). > > I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS. Thank you for responding, Chris: I may be missing something in your reply, but I am *not* wondering how to associate python with the .pdf file extension. That I know how to do. What I want to know is how from within the program that I've told windows to run when the user clicks on the file --- how to access the file that the user wishes to open. Windows must somehow make that available to my program. How to I access it. Tomorrow, I'll try doing it an looping through the sys.argvs and see what's there. maybe it's a simple as passing a path into the called program.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-06-19 11:18 +1000 |
| Message-ID | <mailman.621.1434676699.13271.python-list@python.org> |
| In reply to | #92863 |
On Fri, Jun 19, 2015 at 11:03 AM, Naftali <nmichalowsky@gmail.com> wrote: > I may be missing something in your reply, but I am *not* wondering how to associate python with the .pdf file extension. That I know how to do. What I want to know is how from within the program that I've told windows to run when the user clicks on the file --- how to access the file that the user wishes to open. Windows must somehow make that available to my program. How to I access it. Tomorrow, I'll try doing it an looping through the sys.argvs and see what's there. maybe it's a simple as passing a path into the called program. > Oh! I see what you mean. You should get the full path and name of the file in sys.argv, but if you don't, I think what you need to do is add "%s" to the end of the association definition. My apologies for the prior misunderstanding. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-06-19 02:39 +0100 |
| Message-ID | <mailman.622.1434678004.13271.python-list@python.org> |
| In reply to | #92863 |
On 2015-06-19 02:18, Chris Angelico wrote: > On Fri, Jun 19, 2015 at 11:03 AM, Naftali <nmichalowsky@gmail.com> wrote: >> I may be missing something in your reply, but I am *not* wondering how to associate python with the .pdf file extension. That I know how to do. What I want to know is how from within the program that I've told windows to run when the user clicks on the file --- how to access the file that the user wishes to open. Windows must somehow make that available to my program. How to I access it. Tomorrow, I'll try doing it an looping through the sys.argvs and see what's there. maybe it's a simple as passing a path into the called program. >> > > Oh! I see what you mean. You should get the full path and name of the > file in sys.argv, but if you don't, I think what you need to do is add > "%s" to the end of the association definition. My apologies for the > prior misunderstanding. > I don't think it should be "%s", but "%*". This has more details: https://technet.microsoft.com/en-us/library/bb490912.aspx
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-06-19 11:46 +1000 |
| Message-ID | <mailman.623.1434678393.13271.python-list@python.org> |
| In reply to | #92863 |
On Fri, Jun 19, 2015 at 11:39 AM, MRAB <python@mrabarnett.plus.com> wrote: > I don't think it should be "%s", but "%*". Thanks, it's been a while since I fiddled with Windows associations. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Naftali <nmichalowsky@gmail.com> |
|---|---|
| Date | 2015-06-18 18:22 -0700 |
| Message-ID | <8696771d-2cd2-46f9-9965-088f472426ad@googlegroups.com> |
| In reply to | #92852 |
On Thursday, June 18, 2015 at 5:05:15 PM UTC-4, Naftali wrote: > Long time lurker. > > I'm looking to register a python script as the default pdf reader for windows. I assume I can just register the .py in the section windows section for registering default handlers, but I'm wondering how to access the file from within the program. > > The issue is this: > > We have Java application that outputs user uploaded pdf files. It does this simply by instructing windows to open the downloaded pdf file and windows takes it from there. The data entry person will view the pdf and usually upload it into another part of the system. Problem is the second leg of the system modifies the pdf, and thus crashes when the pdf is protected against writing. Data entry make use of a program to unlock them as needed but it is an extra step and it only comes to their awareness after their client crashes on the locked pdf (because it doesn't make sense to check them proactively. > > I cannot change the Java system. > > What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like). > > I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS. Thank you, Chris.
[toc] | [prev] | [next] | [standalone]
| From | Naftali <nmichalowsky@gmail.com> |
|---|---|
| Date | 2015-06-23 06:39 -0700 |
| Message-ID | <2bba2e7f-ef41-4b08-8768-fa154c219042@googlegroups.com> |
| In reply to | #92852 |
On Thursday, June 18, 2015 at 5:05:15 PM UTC-4, Naftali wrote: > Long time lurker. > > I'm looking to register a python script as the default pdf reader for windows. I assume I can just register the .py in the section windows section for registering default handlers, but I'm wondering how to access the file from within the program. > > The issue is this: > > We have Java application that outputs user uploaded pdf files. It does this simply by instructing windows to open the downloaded pdf file and windows takes it from there. The data entry person will view the pdf and usually upload it into another part of the system. Problem is the second leg of the system modifies the pdf, and thus crashes when the pdf is protected against writing. Data entry make use of a program to unlock them as needed but it is an extra step and it only comes to their awareness after their client crashes on the locked pdf (because it doesn't make sense to check them proactively. > > I cannot change the Java system. > > What I want to do is write a pdf handler to handle windows open instruction. In the script I would run a command line pdf unlocker on the file and open the unlocked file with adobe (or the like). > > I've googled and though I get tons of 'how to open pdf from a python script' I haven't found anything describing how to write and set up my python program to deal with the pdf hand-off from the OS. Just to update, you are correct, Chris, the file short name is passed into sys.argv. didn't need to add anything to the path. But a gotcha -- Windows didn't like my .py, clicking on the pdf causes Windows to complain about 'file x' is not a valid windows executable. I didn't research it so cant speak definitely, but converting the .py to a py2exe correlated with that complaint going away. In the end, though since, making any changes to the program required redoing the py2exe and since this is to be running on a colleagues machine, I ended up putting the handler commands into a .bat file. My hunch is that it's faster that way, too.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-06-24 01:00 +1000 |
| Message-ID | <mailman.730.1435071611.13271.python-list@python.org> |
| In reply to | #93039 |
On Wed, Jun 24, 2015 at 12:26 AM, Jean-Michel Pichavant <jeanmichel@sequans.com> wrote: >> Just to update, you are correct, Chris, the file short name is passed >> into sys.argv. didn't need to add anything to the path. But a gotcha >> -- Windows didn't like my .py, clicking on the pdf causes Windows to >> complain about 'file x' is not a valid windows executable. > > I'm not an expert of windows but you probably need to specify the python interpreter, not the script itself. > > something like > > C:\Python2.7\python.exe yourscript.py %* > > in the windows file association panel. Yep, that's what I'd recommend too. You shouldn't need to py2exe it. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2015-06-23 16:12 -0400 |
| Message-ID | <mailman.734.1435090373.13271.python-list@python.org> |
| In reply to | #93039 |
On Tue, 23 Jun 2015 16:26:28 +0200 (CEST), Jean-Michel Pichavant
<jeanmichel@sequans.com> declaimed the following:
>> Just to update, you are correct, Chris, the file short name is passed
>> into sys.argv. didn't need to add anything to the path. But a gotcha
>> -- Windows didn't like my .py, clicking on the pdf causes Windows to
>> complain about 'file x' is not a valid windows executable.
>
>I'm not an expert of windows but you probably need to specify the python interpreter, not the script itself.
>
>something like
>
>C:\Python2.7\python.exe yourscript.py %*
>
>in the windows file association panel.
>
Need to check the specific install, I've seen two or three different
assoc names used in the past...
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Wulfraed\Documents>assoc .py
.py=Python.File
C:\Users\Wulfraed\Documents>ftype python.file
python.file="C:\Python_x64\Python27\python.exe" "%1" %*
ftype links a "file type" handler to the executable path (note the "%1"
is the placeholder for the script name itself, and arguments to the script
are collected with %*). Assoc then links the extension to the handler (so
you can also assoc .pyc files to the same interpreter).
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-06-23 21:20 +0100 |
| Message-ID | <mailman.735.1435090836.13271.python-list@python.org> |
| In reply to | #93039 |
On 23/06/2015 21:12, Dennis Lee Bieber wrote: > On Tue, 23 Jun 2015 16:26:28 +0200 (CEST), Jean-Michel Pichavant > <jeanmichel@sequans.com> declaimed the following: > >>> Just to update, you are correct, Chris, the file short name is passed >>> into sys.argv. didn't need to add anything to the path. But a gotcha >>> -- Windows didn't like my .py, clicking on the pdf causes Windows to >>> complain about 'file x' is not a valid windows executable. >> >> I'm not an expert of windows but you probably need to specify the python interpreter, not the script itself. >> >> something like >> >> C:\Python2.7\python.exe yourscript.py %* >> >> in the windows file association panel. >> > Need to check the specific install, I've seen two or three different > assoc names used in the past... > > Microsoft Windows [Version 6.1.7601] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\Wulfraed\Documents>assoc .py > .py=Python.File > > C:\Users\Wulfraed\Documents>ftype python.file > python.file="C:\Python_x64\Python27\python.exe" "%1" %* > > ftype links a "file type" handler to the executable path (note the "%1" > is the placeholder for the script name itself, and arguments to the script > are collected with %*). Assoc then links the extension to the handler (so > you can also assoc .pyc files to the same interpreter). > With Python 3.4 or if you've installed the pylauncher independantly. C:\Users\Mark\Documents\MyPython>assoc .py .py=Python.File C:\Users\Mark\Documents\MyPython>ftype python.file python.file="C:\Windows\py.exe" "%1" %* C:\Users\Mark\Documents\MyPython>assoc .pyw .pyw=Python.NoConFile C:\Users\Mark\Documents\MyPython>ftype python.noconfile python.noconfile="C:\Windows\pyw.exe" "%1" %* -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web