Can a program launch AHK? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Evil-e
Posts: 146
Joined: 04 Sep 2018, 11:09

Can a program launch AHK?

09 Jan 2020, 21:53

If I launch Audacity Audio Editor, is there a way that a specific AHK.exe file will be launched as a result? So, can AHK somehow be "notified" a program is running and launch a specific AHK.exe file?

NOTE: This is a right-click menu, so my usual batch file is not gonna work :(

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Can a program launch AHK?

09 Jan 2020, 22:11

Yes. You just need a script running that waits for the Audacity window to appear. Like this:

Code: Select all

loop ; loop so that it's ready to detect Audacity each time it's run
{
	WinWait, ahk_exe audacity.exe
	Run, PathToMyAhkApp.exe
	WinWaitClose, ahk_exe audacity.exe
}
Evil-e
Posts: 146
Joined: 04 Sep 2018, 11:09

Re: Can a program launch AHK?

09 Jan 2020, 22:48

Thank you for the fast response and a really cool idea :)

However, it should resolve one issue, but creates a new one.... lol :) I would rather not open Documents and Settings and manually delete the cache folder, but the trade off is having a program running in the background at all times :( I know.... 1st world problems, right? :thumbup:

This is what I tried and would not launch the batch file which is written to remove the cache directory :(

Code: Select all

loop
{
	WinWait, ahk_exe audacity.exe
	Run, "C:\Program Files\Audacity\Audacity.exe"
	WinWaitClose, ahk_exe audacity.exe
}
sleep, 100
Run, "C:\Program Files\Audacity\Launch Audacity delete temp folder.bat"
sleep, 100
ExitApp
return
The AHK.exe continued to run, after Audacity was closed, but failed to execute the batch file to clear the cache folder. Any thoughts?

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Can a program launch AHK?  Topic is solved

09 Jan 2020, 23:12

There are a couple issues. You said you wanted to wait for Audacity to appear and when it does, you would run a specific AHK file. But instead, the way you show it, you're waiting for Audacity to run and then the program you run is...Audacity. That's supposed to be your AHK script. I don't understand why you're having it run Audacity.

The reason the stuff you added below it never gets executed because of the loop above it. You need it inside the loop. If it's supposed to occur after Audacity is closed, it would look like this:

Code: Select all

loop
{
	WinWait, ahk_exe audacity.exe
	Run, YourAHKFile
	WinWaitClose, ahk_exe audacity.exe
	sleep, 100
	Run, "C:\Program Files\Audacity\Launch Audacity delete temp folder.bat"
}
Note that I didn't include the second sleep command since it really doesn't do anything helpful, and I didn't include the ExitApp because then it won't be ready to act again next time Audacity is run. If you only want it to execute one time, then you don't even need a loop, and it would just be:

Code: Select all

WinWait, ahk_exe audacity.exe
Run, YourAHKFile
WinWaitClose, ahk_exe audacity.exe
sleep, 100
Run, "C:\Program Files\Audacity\Launch Audacity delete temp folder.bat"
Evil-e
Posts: 146
Joined: 04 Sep 2018, 11:09

Re: Can a program launch AHK?

10 Jan 2020, 06:54

It's funny... you are mentioning things I thought about, but not until after I posted :)

I may have misspoken above, as my little brain works faster than my fingers and don't express myself as intended [get's off of couch, Dr. Freud is not in today]

The ExitApp is a hold over from a copy/paste hundreds of AHK.exe files that I have created. In all cases, until now, I want AHK.exe to close when the program is exited Audacity being the sole exception. Yes, I corrected the script as follows:

Code: Select all

loop
{
	    WinWait, ahk_exe audacity.exe
	    Run, "C:\Program Files\Audacity\Audacity.exe"
	    WinWaitClose, ahk_exe audacity.exe
        sleep, 100
        Run, "C:\Program Files\Audacity\Launch Audacity delete temp folder.bat"
}
return
This works exactly as you said and clears cache upon exiting Audacity and AHK.exe continues to run :) Purrrrfect, except I don't use Audacity frequently enough to warrant AHK.exe running at all times :(

I do a lot of gaming and frequently go into Documents and Settings folder to back up my save files. I am just anal about seeing empty cache folders in there and have many games that create cache folders, but all of them have a batch file to remove them when game is exited. As much as I don't like empty cache folders on my computer, I am more anal about programs that run constantly on my computer.

Your idea is exactly what I asked for, but the trade off is a constantly running program and not worth it to me :( I thank you for your help and will save this script, as I may change my mind or find another use for it in the future :)

Many thanks, @boiler :beer:

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Return to “Ask For Help”

Who is online

Users browsing this forum: felipe93, marqqer and 66 guests