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
  501 Server cannot accept argument anna17 0 191 Apr-11-2024, 01:08 AM
Last Post: anna17
  How to accept facebook cookies using python selenium? pablo86ad 0 198 Apr-06-2024, 09:19 PM
Last Post: pablo86ad
  How do I handle escape character in parameter arguments in Python? JKR 6 1,162 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 11,065 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  accept command line argument mg24 5 1,325 Sep-27-2022, 05:58 PM
Last Post: snippsat
  python call stored procedure with two parameter mg24 4 1,522 Sep-27-2022, 05:02 AM
Last Post: deanhystad
  [SOLVED] Input parameter: Single file or glob? Winfried 0 1,587 Sep-10-2021, 11:54 AM
Last Post: Winfried
  How to fill parameter with data from multiple columns CSV file greenpine 1 1,665 Dec-21-2020, 06:50 PM
Last Post: Larz60+
  Hi Guys, please help me to write SAS macro parameter equivalent code in Python Manohar9589 2 2,603 Jun-14-2020, 05:07 PM
Last Post: Larz60+
  compiled cpython output wrong version bigrockcrasher 0 1,513 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