Executable Path to Mac App

In the py2app / Mac application package, is there a way to create another instance of the same application from the application by passing different command line arguments?

or given the Mac app package, how can I run it from the command line and pass some arguments?

Edit1: forking is a limited option that may not work with a package of third-party executables with the + application. I need to run this on Mac and Windows.
Edit2: The question is how to run the associated python script using the subprocess module

Details:

I am using py2app to create an application package for my appilcation. My application is in two parts

  • MainApp: user interface
  • BackgroundApp: a background process that does the real work

Both MainApp and BackgroundApp are implemented as a python script, and in fact they are the same python script with a different command line, for example.

python myapp.py python myapp.py --backgroundprocess 

Therefore, when I run python myapp.py , it automatically starts the background process based on the path to the program, but since I now connected my application as py2app, I'm not sure which executable I need to call and pass the --backgroundprocess parameter?

What i tried

  • $ open MyApp.app/ this opens the application, but I can not pass arguments to it, since they will be arguments for an open command and will not be passed to my application

  • $ MyApp.app/Contents/MacOS/MyApp --backgroundprocess opens the application, but not the backgroun process, because it seems that the arguments are not passed to the application

he also gives an error

  Traceback (most recent call last): File "/Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/run.py", line 4, in <module> from renderprocess import RenderEngineApp File "renderprocess/RenderEngineApp.pyc", line 6, in <module> File "wx/__init__.pyc", line 45, in <module> File "wx/_core.pyc", line 4, in <module> File "wx/_core_.pyc", line 18, in <module> File "wx/_core_.pyc", line 11, in __load ImportError: dlopen(/Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/lib/python2.5/lib-dynload/wx/_core_.so, 2): Library not loaded: @executable_path/../Frameworks/libwx_macud-2.8.0.dylib Referenced from: /Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/lib/python2.5/lib-dynload/wx/_core_.so Reason: Incompatible library version: _core_.so requires version 7.0.0 or later, but libwx_macud-2.8.0.dylib provides version 2.6.0 

Conclusion: It seems that it is impossible to Run the application in OS X with the command line

open contains no arguments.

+6
python macos py2app
source share
3 answers

How to find cwd and execute an arbitrarily set binary First put the binary in AppName.app/Contents/Resources, then run this code from the python script:

 import subprocess process=subprocess.Popen((os.getcwd() + "/3rd_party_binary","--subprocess")) process.poll() # is running? 

How to properly create two versions of your python application

Fork is an old tried and tested way to do this on MacOSX (unix)

 #!/usr/bin/env python import os, sys pid = os.fork() if pid: # we are the parent background_process.start() os.waitpid(pid, 0) # make sure the child process gets cleaned up else: # we are the child gui_app.start() sys.exit(0) print "parent: got it; text =", txt 

Multiprocessing in Python seems to work on windows that I think you are interested in (?).

+1
source share

Create one application, and then just call -bakgroundproccess for the application, and then create a shortcut for the backgroundprocess flag. Or two different application files. Ether is a good way

0
source share

I could not get py2app to work, but the application executable is in AppName.app/Contents/MacOS/AppName . You can check the file AppName.app/Contents/Info.plist for the key <key>CFBundleExecutable</key> , it points to executable packages in the AppName.app/Contents/MacOS folder.

So you can name it AppName.app/Contents/MacOS/AppName --backgroundprocess .

If you want BackgroundApp execute a background process without any arguments, there are two options: a) make a package from a python script that starts the background process without any arguments; b) change the <key>CFBundleExecutable</key> in the Info.plist file to say BackGroundApp_shell and shell the script Contents/MacOS/BackgroundApp_shell read:

 #!/bin/sh `dirname "$0"`/BackgroundApp --backgroundprocess 

provided that the BackgroundApp executable.

0
source share

All Articles