MaxQ
MaxQ

Reputation: 605

How do I give additional arguments when using Python to open on application on Mac?

I'm playing around with Flightgear and I'd like a way to launch /Applications/FlightGear.app from a Python script with a specific aircraft, but it's not accepting additional parameters.

This works:

os.system("open /Applications/FlightGear.app/Contents/MacOS/fgfs")

This does, but does not select the aircraft... I've tried both with and without hyphens in front of 'aircraft'.

os.system("open /Applications/FlightGear.app/Contents/MacOS/fgfs --args aircraft=777-200ER")

For references,

pic
(source: flightgear.org)

Upvotes: 2

Views: 589

Answers (2)

Andrew Jaffe
Andrew Jaffe

Reputation: 27077

On OS X, open is to run an application. To run a command-line program you would just do it like on unix/linux, assuming that /Applications/FlightGear.app/Contents/MacOS/fgfs is actually a runnable program.

I can't test it for this particular case, but I think you want os.system() to run exactly what you would type at the command-line prompt. Hence,

os.system("/Applications/FlightGear.app/Contents/MacOS/fgfs --aircraft=777-200ER")

Upvotes: 0

Dustin Oprea
Dustin Oprea

Reputation: 10236

Something like this. Sometimes some of the arguments will have to be combined, depending on their relation to each other.

import subprocess
p = subprocess.Popen(['open', '/Applications/FlightGear.app/Contents/MacOS/fgfs', '--args', 'aircraft=777-200ER'])
if p.wait() != 0:
  raise EnvironmentError()

This is basic information that could've been found simply by searching "python run command" in Google. SO isn't just a tool for the lazy.

Upvotes: 2

Related Questions