0

I'm trying to create a task whereby when one application is closed, another is automatically closed.

For instance, I'm using the Atom.io text editor with the Kite plugin (code AI assistant) on Windows 10.

When I open Atom, kited.exe auto-starts, however when I close Atom, Kite remains running in the background. It consumes a non-trivial amount of CPU and memory so I'd like to have it automatically shut down when I close Atom.

My thought process is to approach this as a scheduled task that triggers on an event. The event trigger is closing Atom. The task is running a PowerShell script to shut down the Kite: stop-process -name kited

This question is very similar to Trigger a PowerShell Script from a Windows Event however I've looked through the Event Viewer and there does not appear to be a recorded Event ID of when third-party apps are initiated/terminated.

In summary - I'm asking for help with defining this event (closing Atom) such that it triggers the PowerShell command stop-process -name kited.

Also open to completely alternative approaches to get the job done. I just want Kite to close when I close Atom.

3
  • Although I haven't had this EXACT scenario, I have solved this problem more than once. My initial approach would be to launch Atom from a batch file (batch file minimized) and wait for it to exit. When Atom exits, the batch would then kill the extra process. If I hated the extra icon, I would use JScript/WSH to launch that part hidden so I didn't see it.. but I really wouldn't care. I could tell you HOW.. but that is a good exercise for the reader. :) If you want more help with this approach and need help.. just ask. Commented Dec 18, 2020 at 17:02
  • BTW, my approach might not work.. some apps launch and then launch another thingy and exit. This is rare and I doubt Atom works that way. Start by launching atom from the command line using start /wait <PATH_TO_ATOM> and see that the cmd prompt hangs until it exits. If it does, this will work without a more creative solution. Commented Dec 18, 2020 at 17:05
  • @SeñorCMasMas thanks for the hint, I will try and see how I do!
    – McQuestion
    Commented Dec 19, 2020 at 4:34

1 Answer 1

0

I solved this problem with a Python script rather than PowerShell. Thanks @SeñorCMasMas for the suggestion.

Psuedocode: Open Atom; List All Running Apps; If Atom in List > Continue Loop; Else > Close Kite

import subprocess, psutil
from time import sleep

subprocess.run(<path to atom.exe>)

while True:
    processes = [p.name() for p in psutil.process_iter()]
    if 'atom.exe' in processes:
        sleep(5)
        continue
    else:
        subprocess.run('tskill kited')
        break

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .