0
votes

I am trying to make an AHK script open another program everytime it is started. The problem is, I don't want this to happen if that other program is already opened.

Here's what seems to be supposed to be working, but isn't : (this section is placed at the very top of my script)

SetTitleMatchMode, 2
#IfWinNotExist, Microsoft Excel - myExcelFile.xls
Run C:\myExcelFile.xls
#IfWinExist
;REST OF MY SCRIPT GOES HERE

What should be happening :

If the window "Microsoft Excel - myExcelFile.xls" is not opened, run it. If not, do not.

What is happening :

Whether it is opened or not, it will try to run it again.

1
I generally recommend reading the docs before asking a question on SO. There, you will read that #IfWinNotExist creates context-sensitive hotkeys and hotstrings. You are looking for IfWinNotExist, without the # at the beginning, which checks if a matching window exists.MCL

1 Answers

0
votes

So yeah, even though I had read the documentation, I had understood that the difference between #IfWin and IfWin was whether they were used inside or out of a specific hotkey. To my understanding, "creates context-sensitive hotkeys and hotstrings" also included "context-sensitive auto-execution" (when code is not inside a hotkey)

Indeed I was wrong and the solution is to remove the #.