For the past month I've been writing a desktop application for MacOS using Python. It requires opening files and saving compressed data to them. This application creates files using a my own made up extension, so the files are not usable for for other applications. I have almost everything figured out. However, I want to make it so that I can right click on a file with the extension and open it with my python application. I tried using sys.argv to get any arguments for the path of the file to open, but that doesn't work. I know there has to be a way. Preferably there's a builtin variable that is easy to use, but I haven't found anything that helps.
Any help would be useful.
Thanks.
Related
I am working with Python 3.6.6 and need to display several pdf-files in the browser.
I tried several pdf files and got 2 different results.
For example:
import webbrowser
webbrowser.open('https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf')
opens a new tab in my browser and displays the file.
Other files are downloaded immediatelly, instead of displaying in a new tab in the browser.
I want to know the reason for, why some files are downloaded automatically and others are displayed in the browser, where I can manually download the file.
I need a solution where I can force the file to open in the browser.
I already read through this question but it seems it is more restricted to HTML.
One last thing I noticed. If I try to download any pdf file from the internet it opens the file in a new tab. The problem with downloading them only appears with files which are saved on a webserver within my company.
Is this just a missing configuration on the webserver?
If yes, is it anyhow possible to get around this configuration using python?
It's the web-browser's decision whether to put the file in the downloads directory (and not display it) or whether to cache the file and open it in-browser. As such, do not use the web-browser installed on the end-user's system.
Instead, have your program include its own web-browser. Open the pdf (and everything else your program displays) in your program's web-browser. That way, you can always modify your program's web-browser to view files in-browser instead of saving to the downloads directory.
Several free open-source web-browsers are available on the market. Just use one of them.
I'm new to both Python and MicroPython, but i'm getting the hang of this interesting approach at embedded programming!
After creating a new file with the PyBoard, I was wondering whether there is a clever way to refresh the
Windows Directory of the representation of the PyBoard flashDir, and then seeing the change in the windows directory.
Currently, i have to turn off and reload the PyBoard to see the change in a windows directory.
I am aware that i am able to see the file using os.listdir() in a REPL.
I am having a problem with PyCharm (Community Edition) in that, when I open a .py file in the program, I can happily read and write in the file as usual, however when I click out of PyCharm (to look my emails for example) and then click back into it to carry on with my code, the file automatically closes and the project tree structure collapses (so I have to re-open it every time).
So far I have tried changing the tab limit to a high number, but this doesn't seem to help (and it shouldn't be related, since this happens when I open just one file).
I had the same issue before. I'm assuming you're connected to a network shared folder via UNC path (e.g. \\foo\bar\)?
If so, it is not currently supported. You'll need to map your network folder and give it a Drive letter. Then load up your project using the mapped drive, and it'll work like a charm.
If that's not the scenario though, please give us more information.
I am working on a project for my company and I have reached a dead end.
I am trying to find a way to be able to decide whether to allow or block file writing to an external drive based on the content written.
The project is creating a basic DLP system.
I have tried using pydbg to debug Windows explorer, this worked partially but was very unstable and it doesn't work globally (ex. file write with cmd).
The solution can be in any language (Python preferred).
Any kind of help would be great!
I am making an app in python, which is able to open different file types. This code is running fine on eclipse while passing filename which I want to open and configuration file as arguments respectively selectedFileName=(sys.argv)[1]
cfgFile=(sys.argv)[2]. Now I converted this into application by using py2app. So, the issue is how to deal with arguments, as different file types need to be open through app and this app also needs configuration file while processing. Through py2app, in terminal passing this command open -a myapp.app selectedFileName config.cfg opens the file as expected. But, What I want is to directly open file of any extension without the use of terminal. Is openwith for opening file possible in this case, then how?. What changes I have to make in code for passing arguments for both? I also want to distribute this app to others.
You can use py2app. It makes a standard app. All it needs is a python script and setup.py.
Platypus
You might want to have a look at Platypus. It's intended to create Mac .app bundles from shell scripts. The documentation has some information on how to accept files that looks like it should be applicable to you. I haven't tested it out, but you should be able to run your script by dropping files onto the icon, and possibly using the Open With menu as well.