ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: Close/run a program when another program is run/closed

(1/2) > >>

Phoenix232:
The idea is to close/kill Program 1 as Program 2 starts and then when Program 2 is closed, Program 1 is started again. Thinking this might be an easy task I've been trying to modify some scripts I found here but without at any success at all because I'm really new at AHK.

wraith808:
Are either one of the programs in any danger of idle waits for user interaction?  i.e. trying to close notepad with text in it?  Just figuring it would be a good question for whomever picks it up.

skwire:
How did you want to match the program(s)?  Process name?  Window title?

skwire:
At any rate, here's an AHK snippet demonstrating how to do it with process names.  This can be easily adapted to work with window titles instead.


--- Code: Autohotkey ---#PersistentDetectHiddenWindows, On sProgram1 := "notepad.exe"sProgram2 := "calc.exe"nSeconds  := 1SetTimer, Timer, % nSeconds * 1000Return Timer:{    Process, Exist, % sProgram1    myProgram1PID := ErrorLevel    Process, Exist, % sProgram2    myProgram2PID := ErrorLevel        If ( myProgram2PID )    {        Process, Close, % myProgram1PID    }    Else    {        If ( ! myProgram1PID )        {            Run, % sProgram1        }    }}Return

Phoenix232:
At any rate, here's an AHK snippet demonstrating how to do it with process names.  This can be easily adapted to work with window titles instead.


--- Code: Autohotkey ---#PersistentDetectHiddenWindows, On sProgram1 := "notepad.exe"sProgram2 := "calc.exe"nSeconds  := 1SetTimer, Timer, % nSeconds * 1000Return Timer:{    Process, Exist, % sProgram1    myProgram1PID := ErrorLevel    Process, Exist, % sProgram2    myProgram2PID := ErrorLevel        If ( myProgram2PID )    {        Process, Close, % myProgram1PID    }    Else    {        If ( ! myProgram1PID )        {            Run, % sProgram1        }    }}Return-skwire (August 02, 2017, 02:36 PM)
--- End quote ---

This is pretty close of what I was thinking. It's amazing how many lines of code you used to do this. No matter how much I tried I couldn't make it run and even if I could I don't think it would be close to have few lines like yours do. Thank you very much for this.

Navigation

[0] Message Index

[#] Next page

Go to full version