Python Forum

Full Version: I need my compiled Python Mac app to accept a file as a parameter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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>
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)
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.