Page 1 of 1

Posted: 04 Feb 2018, 09:24
Hi !

New with autohotkey, I don't know why I didn't check it before ! It's brilliant !

I need help for what I'd like to achieve... I already spend hours by searching but... No luck.

I'm a musician, Cubase user. I ALWAYS forget to launch an application called asiolinktool when I load my current cubase project (I always load it by clicking on the cubase project saved file).
I'd like asiolinktool.exe to launch each time I lauch cubase... And if possible ... Only if asiolinktool.exe is not already running. (But first, just launching it at the same time I run cubase).

I made this :

#IfWinExist ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe

But when I run the .ahk script, it lauch immediatly asiolinktool.exe ! It's not exactly what I wished.... I'd like it to launch only if I lauch cubase !

If any one could help me... It would be nice... Thanks a lot !

PS : I went to read ifwinactive / exist documentation... And much more !

Posted: 04 Feb 2018, 10:08
Try the command Ifwinexist instead of the directive #ifwinexist (https://autohotkey.com/docs/commands/_IfWinActive.htm). The latter only affects context-sensitive hotkeys and hotstrings which you don't have in your script. The first is more like a normalif-statement which executes the next code line conditionally (or more lines by using code blocks {...} ).

Code: Select all

``````#Persistent
setTimer, checkCubase, 1000		; check every second (1000 ms), if Cubase is running
return

checkCubase:
IfWinExist ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe				; if Cubase is running...
IfWinNotExist ahk_exe C:\Program Files (x86)\ASIOLinkPro\x64\asiolinktool.exe		; ... check if the tool is already running, if not...
Run, C:\Program Files (x86)\ASIOLinkPro\x64\asiolinktool.exe				; ...run the tool
return``````
To check constantly if Cubase is running, you could use SetTimer. But there are probably many of other ways...

Posted: 04 Feb 2018, 10:44
Great ! Excellent !

Works perfectly. Now, I'd like to close the script when cubase & asiolinktool are running...

I added this (But doesn't work !) :

IfWinExist ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe, C:\Program Files (x86)\ASIOLinkPro\x64\asiolinktool.exe
ExitApp

Or this :

IfWinExist ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe
ExitApp

I don't find a logical AND to say "if cubase and asiolinktool are running, close the script.

I go to search......

Posted: 04 Feb 2018, 11:20
There are again many ways, but that might do it

Code: Select all

``````#Persistent
setTimer, checkCubase, 1000		; check every second (1000 ms), if Cubase is running
return

checkCubase:
IfWinExist ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe				; if Cubase is running...
IfWinNotExist ahk_exe C:\Program Files (x86)\ASIOLinkPro\x64\asiolinktool.exe		; ... check if the tool is already running, if not...
{
Run, C:\Program Files (x86)\ASIOLinkPro\x64\asiolinktool.exe				; ...run the tool
Sleep, 200
ExitApp															; now that both are running, exit
}
return``````
A method with a logical and could work with the function version of Winexist(), I guess:
if WinExist("ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe") and WinExist("ahk_exe C:\Program Files (x86)\ASIOLinkPro\x64\asiolinktool.exe")

Posted: 04 Feb 2018, 11:28
But I would keep the script running (perhaps even adding it to startup), because if you have to start the script again to monitor Cubase, you might forget to start the script in the first place; and that might defeat the whole purpose of the script

If it supposed to work only once as soon as Cubase is running, you probably could get away with a simple Winwait instead of a timer.

Btw, that:

Code: Select all

``````IfWinExist ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe
ExitApp``````
actually works like a logical and...

Posted: 04 Feb 2018, 12:53
Yes ! Sure I'll load it on windows startup.

The problem is that I still see the autokey icon in the systray... Is it normal ? Doesn't it mean that the script is still running ?
gregster wrote:Btw, that:

Code: Select all

``````IfWinExist ahk_exe C:\Program Files\Steinberg\Cubase 9.5\Cubase9.5.exe
ExitApp``````
actually works like a logical and...
But look at my previous message ! That's what I did ! Aarrrh ! But ... Anyway... I've got the same behavior as with mine = it seems to still run.

I the space you add on the begining of line 2 & 3 important ?

Posted: 04 Feb 2018, 13:14
The indentation is just to make clear how the ifs are stacked. And I saw your previous message, but results may vary depending on where you actually put that piece of code. I can test later if my (untested) script from above works. But if it starts the tool, I don't see how it could miss theExitApp.

But like I said, if you are starting the script via startup and only expect it to work the first time, Cubase is running, you could try WinWait:

Code: Select all

``````Winwait, ahk_exe Cubase9.5.exe		; Wait for Cubase
ExitApp		; optional, if this the actual end of your script``````
That should wait for Cubase to run and procede as soon as the Cubase window exists.

Edit: Changed the ahk_exe part for more flexibility.

Posted: 04 Feb 2018, 13:20
Does ahk_Exe work like that? I would have expected you'd need to just call it ahk_exe Cubase9.5.exe. What does Window Spy, which can be accessed by right-clicking the tray icon (by the system clock) of a running script, say the ahk_exe title would be on these programs?

I skimmed over the last several responses though. Might be other mistakes to address.