tez
tez

Reputation: 5300

starting and stopping mac applications using python

os.system("open /Applications/Mail.app")

I'm able to open mac applications using the above statement(though not able to open applications which include spaces in their name. eg.Photo Booth).

But I cannot find a method to close apps.How do i do that? Googled a lot but all the solutions mentioned were for windows.

Upvotes: 0

Views: 123

Answers (1)

paxdiablo
paxdiablo

Reputation: 881653

With respect to opening applications with spaces, you'll probably find you can do something like:

os.system("open \"/Applications/Photo Booth.app\"")

or:

os.system('open "/Applications/Photo Booth.app"')

The reason why there's probably not an equivalent close command is because it unbalanced.

Opening two applications with the same parameters is easily done, you just create two separate processes. However, when you then want to close one, which gets hit? They both have the same name.

You can look into using kill once you establish the process ID of the process you're trying to get rid of, or you can use osascript to tell applications to exit:

osascript -e 'tell application "PaxsDodgyApp" to quit'

Upvotes: 1

Related Questions