I need my compiled Python Mac app to accept a file as a parameter - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I need my compiled Python Mac app to accept a file as a parameter (/thread-26667.html) |
I need my compiled Python Mac app to accept a file as a parameter - Oethen - May-09-2020 I compiled my Python script to a Mac app. I need to have accept a file as a parameter (drag and drop onto app). I know I need to edit the info.plist and I have tried (code below) but it's not working. When I pass the file as a parameter in the Terminal to the .py script, it works so I know it's not my Python code. If anyone can lend a hand, that would be great! Thanks! <key>CFBundleTypeExtensions</key> <array> <string>pdf</string> </array> <key>CFBundleTypeIconFile</key> <string>generic.icns</string> <key>CFBundleTypeName</key> <string>IMG Disk Image</string> <key>CFBundleTypeRole</key> <string>Viewer</string> RE: I need my compiled Python Mac app to accept a file as a parameter - Larz60+ - May-09-2020 In your code, add arguments with Argparse: https://docs.python.org/3/library/argparse.html of for simple file grab, import sys ... # add to your initialization: filename = sys.argv[1] # (index 0 is script name) RE: I need my compiled Python Mac app to accept a file as a parameter - Oethen - May-10-2020 Thanks Larz60 but I already have my code set up to take command line parameters, and it works fine when compiled on Windows and at the terminal on Mac, but I want to be able to drag and drop a PDF file on the compiled Mac app or send a PDF file to it. When I do the app doesn't recognize the parameter. I know it has something to do with the info.plist but the XML code I am using to attempt to allow it to accept parameters does not work. |