OSX: Launching multiple instances of an app and pa

2019-04-09 20:55发布

There is a program I need to launch multiple times and pass it different arguments each time. To do this I tried writing a simple python script as follows:

import sys, os
from os.path import join

# This works, but will not launch twice
os.system('./AppName.app -AppCommandLineArg')

# This allows launching two instances but without command line arguments
os.system('open --new --background ./AppName.app')

# Attempt #1
os.system('open --new --background ./AppName.app -AppCommandLineArg')

# Attempt #2
os.system('open --new --background "./AppName.app -AppCommandLineArg"')

# Attempt #3
os.system('open --new --background "./AppName.app/Contents/MacOS/AppName -AppCommandLineArg"')

The reason I'm using 'open' is to be able to launch the app multiple time. Is 'open' the correct command to use? Any suggestions on how to do this? Working with linux/mac is very new to me.

Thanks!

Edit - Here is the code that solved the problem for me:

p0   = subprocess.Popen(['./AppName.app/Contents/MacOS/AppName', '-AppCommandLineArg'])
p1   = subprocess.Popen(['./AppName.app/Contents/MacOS/AppName', '-AppCommandLineArg'])

Cheers!

1条回答
Root(大扎)
2楼-- · 2019-04-09 21:09

Yes, open is the correct way of launching applications on Mac OS X. See the man page for more information. I'm not on a Mac right now, so I can't test this, but I believe the following should work:

os.system('open -n ./AppName.app --args -AppCommandLineArg')
查看更多
登录 后发表回答