Python Forum
I need my compiled Python Mac app to accept a file as a parameter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need my compiled Python Mac app to accept a file as a parameter
#1
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>
Reply
#2
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)
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Executable file compiled by PyInstaller does not work on Windows 7 amusaber 1 1,570 Jul-11-2024, 02:59 PM
Last Post: DeaD_EyE
  501 Server cannot accept argument anna17 0 909 Apr-11-2024, 01:08 AM
Last Post: anna17
  How to accept facebook cookies using python selenium? pablo86ad 0 1,280 Apr-06-2024, 09:19 PM
Last Post: pablo86ad
  How do I handle escape character in parameter arguments in Python? JKR 6 5,180 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 17,199 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  accept command line argument mg24 5 2,254 Sep-27-2022, 05:58 PM
Last Post: snippsat
  python call stored procedure with two parameter mg24 4 4,472 Sep-27-2022, 05:02 AM
Last Post: deanhystad
  [SOLVED] Input parameter: Single file or glob? Winfried 0 1,995 Sep-10-2021, 11:54 AM
Last Post: Winfried
  How to fill parameter with data from multiple columns CSV file greenpine 1 2,516 Dec-21-2020, 06:50 PM
Last Post: Larz60+
  compiled cpython output wrong version bigrockcrasher 0 1,904 Feb-25-2020, 06:31 PM
Last Post: bigrockcrasher

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020