Python quit and restart an app

Posted on
Sun Jun 04, 2017 6:47 pm
farberm offline
Posts: 393
Joined: Feb 24, 2008

Python quit and restart an app

I am trying to write a script to quit and then restart and app. Do not see any examples of this. I think this may start an app but do not see one to stop and app.

import os
os.system("open /Applications/Safari.app")

Posted on
Sun Jun 04, 2017 9:27 pm
kwijibo007 offline
Posts: 325
Joined: Sep 27, 2013
Location: Melbourne, Australia

Re: Python quit and restart an app

You could try:

import subprocess
subprocess.call(['osascript', '-e', 'tell application "Safari" to quit'])

It's actually calling an apple script command. I'm not in a position to test but it should work.

Pete


Sent from my iPad using Tapatalk

Posted on
Sun Jun 04, 2017 9:37 pm
kwijibo007 offline
Posts: 325
Joined: Sep 27, 2013
Location: Melbourne, Australia

Re: Python quit and restart an app

Come to think of it, this is probably better...

os.system('pkill -9 "Safari"')

Pete


Sent from my iPad using Tapatalk

Posted on
Mon Jun 05, 2017 6:58 pm
farberm offline
Posts: 393
Joined: Feb 24, 2008

Re: Python quit and restart an app

I just tried this and I do not see the application stop and restart? Suggestions?

import os
os.system('pkill -9 "noip autorun"')

import os
os.system("open /Applications/noip autorun.app")

Posted on
Mon Jun 05, 2017 7:11 pm
johnfdl offline
Posts: 177
Joined: May 18, 2017
Location: Atlanta, GA USA

Re: Python quit and restart an app

I run a very similar apple script every day to close and relaunch an app. Here's the syntax I use:

do shell script "pkill -9 Cisco AnyConnect Secure Mobility Client"

and the relaunch is:

do shell script "open -a 'Cisco AnyConnect Secure Mobility Client'"

Mine happens to run on a schedule that I have in Calendar app so I can't speak on how to embed in Indigo.

Posted on
Mon Jun 05, 2017 7:13 pm
farberm offline
Posts: 393
Joined: Feb 24, 2008

Re: Python quit and restart an app

thx

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests