Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

WinActivate with PID problem with Reaper.exe

  • Please log in to reply
2 replies to this topic
  • Members
  • 6 posts
  • Last active: Oct 14 2015 06:32 PM
  • Joined: 21 Jul 2015

Hello.  I'm using a Zotac Mini-PC with Windows 8.1 and AutoHotkey v1.1.22.03 (Unicode 32-bit).  I'm using Windows Task Scheduler to run the compiled AutoHotkey Executable at a scheduled time.  I'm relatively new to AutoHotkey.


The goal of the AHK executable is to:

1) run the program Reaper.exe

2) wait seven seconds

3) press the space bar

4) wait 307 seconds for the song to play

5) quit reaper

6) exit the PAD1.exe executable


If I run the Executable (PAD1.EXE) from Windows Explorer, everything behaves as expected.  It runs, plays, waits and closes everything well.


However, I run into a problem when PAD1.EXE is launched from Windows Task Scheduler after a PC reboots.  The Scheduler launches the PAD1.EXE which in turn starts the Reaper.exe application, but the Reaper task doesn't appear to be active.  The Send, {space} line in the script never seems to get executed.


I've looked at the boards and have tried to impliment WinActivate, but it doesn't seem to work.  Can you tell me where I'm going wrong?


Many thanks for looking at this.



; First determine the location of reaper.exe
; If reaper.exe is in the 32 bit program files folder
IfExist, C:\Program Files\REAPER\reaper.exe
    ; assign reaper_exe the value of the 32 bit folder
    reaper_exe = C:\Program Files\REAPER\reaper.exe
; If reaper.exe is in the 64 bit program files folder
IfExist, C:\Program Files (x86)\REAPER\reaper.exe
    ; assign reaper_exe the value of the 64 bit folder
    reaper_exe = C:\Program Files (x86)\REAPER\reaper.exe
; run the executable with the RPP project file as the arguement
Run, "%reaper_exe%" "%USERPROFILE%\Documents\REAPER Media\PAD1.RPP"
Sleep, 7000       ; giving 7 seconds time before action
; Determine if reaper.exe launched successfully
; Assign "reaper.exe" to the variable Processname
; Determine if a process containing Processname exists
Process, Exist, %Processname%
; If the process does NOT exist, send an eMail with ERROR to advise of the problem
; Return to stop the execution of this script and close PAD1.EXE
If !ErrorLevel
    Run "C:\Program Files\SendEmail\sendEmail.exe" ;TRUNCATED FOR BOARD POSTING
;Assign to the variable Exp_pd the PID from ErrorLevel
Exp_pd := ErrorLevel
;If the Window is not active for the PID in Exp_pd then use WinActivate
IfWinNotActive, % "ahk_pid " Exp_pd
    Run "C:\Program Files\SendEmail\sendEmail.exe" ;TRUNCATED FOR BOARD POSTING
    WinActivate, ahk_pid %Exp_pd%
Send, {space}     ; the space key will start REAPER playing the opened project (PAD1.RPP)
Sleep, 307000     ; giving 5 minutes 07 seconds for the 5 minutes 00 seconds song to play
Send, ^q    ; quit REAPER
Sleep, 3000    ; giving 3 seconds to close REAPER
Exit        ; exit the current thread and close this PAD1.exe

  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

What happens if you use WinActivate, ahk_exe reaper.exe or WinActivate, ahk_exe %processname% on that 7th from last line? (And I suppose also try it for the IfWinNotActive, line.

  • Members
  • 6 posts
  • Last active: Oct 14 2015 06:32 PM
  • Joined: 21 Jul 2015
✓  Best Answer


Thanks for the reply.  I got the same result, but poking around made me realize the problem.  The issue is the SendEmail statement: 

Run "C:\Program Files\SendEmail\sendEmail.exe" ;TRUNCATED FOR BOARD POSTING

It takes a few seconds to execute, then returns with a success message.  It seems that the success message interfers with the following line:

Send, {space}

So in between the Run ..... SendEmail and the WinActivate lines I added a new sleep line that seems to have fixed the problem.

Sleep, 8000 ; give eight seconds for the SendEmail to finish and post the success message.

The sleep time is not too critical for me.  This is running on an unattended PC.

Thanks again for your help.