Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • October 20, 2017, 10:17 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Close/run a program when another program is run/closed  (Read 643 times)

Phoenix232

  • Supporting Member
  • Joined in 2017
  • **
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
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

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 8,945
    • View Profile
    • Donate to Member
Re: IDEA: Close/run a program when another program is run/closed
« Reply #1 on: August 02, 2017, 01:16 PM »
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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,824
    • View Profile
    • Donate to Member
Re: IDEA: Close/run a program when another program is run/closed
« Reply #2 on: August 02, 2017, 02:09 PM »
How did you want to match the program(s)?  Process name?  Window title?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,824
    • View Profile
    • Donate to Member
Re: IDEA: Close/run a program when another program is run/closed
« Reply #3 on: August 02, 2017, 02:36 PM »
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 [Select]
  1.  
  2. sProgram1 := "notepad.exe"
  3. sProgram2 := "calc.exe"
  4. nSeconds  := 1
  5. SetTimer, Timer, % nSeconds * 1000
  6. Return
  7.  
  8. Timer:
  9. {
  10.     Process, Exist, % sProgram1
  11.     myProgram1PID := ErrorLevel
  12.     Process, Exist, % sProgram2
  13.     myProgram2PID := ErrorLevel
  14.    
  15.     If ( myProgram2PID )
  16.     {
  17.         Process, Close, % myProgram1PID
  18.     }
  19.     Else
  20.     {
  21.         If ( ! myProgram1PID )
  22.         {
  23.             Run, % sProgram1
  24.         }
  25.     }
  26. }
  27. Return

Phoenix232

  • Supporting Member
  • Joined in 2017
  • **
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Re: IDEA: Close/run a program when another program is run/closed
« Reply #4 on: August 02, 2017, 05:44 PM »
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 [Select]
  1.  
  2. sProgram1 := "notepad.exe"
  3. sProgram2 := "calc.exe"
  4. nSeconds  := 1
  5. SetTimer, Timer, % nSeconds * 1000
  6. Return
  7.  
  8. Timer:
  9. {
  10.     Process, Exist, % sProgram1
  11.     myProgram1PID := ErrorLevel
  12.     Process, Exist, % sProgram2
  13.     myProgram2PID := ErrorLevel
  14.    
  15.     If ( myProgram2PID )
  16.     {
  17.         Process, Close, % myProgram1PID
  18.     }
  19.     Else
  20.     {
  21.         If ( ! myProgram1PID )
  22.         {
  23.             Run, % sProgram1
  24.         }
  25.     }
  26. }
  27. Return

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.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,824
    • View Profile
    • Donate to Member
Re: IDEA: Close/run a program when another program is run/closed
« Reply #5 on: August 02, 2017, 05:49 PM »
You're very welcome.  Please let us know if you need further help.   :Thmbsup:

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,824
    • View Profile
    • Donate to Member
Re: IDEA: Close/run a program when another program is run/closed
« Reply #6 on: August 07, 2017, 02:21 PM »
@Phoenix232: If you don't require further help on this, do you mind if I move this to the Finished section?

Phoenix232

  • Supporting Member
  • Joined in 2017
  • **
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Re: IDEA: Close/run a program when another program is run/closed
« Reply #7 on: October 19, 2017, 11:33 AM »
@Phoenix232: If you don't require further help on this, do you mind if I move this to the Finished section?

Not at all. Sorry for the late response.