Page 1 of 1

winexist can't detect %UserProfile%

Posted: 18 Apr 2022, 04:21
by vkhu
I have a script like so

Code: Select all

DetectHiddenWindows, On
DetectHiddenText, On
SetTitleMatchMode, 2

#If !WinExist("%UserProfile%\Dropbox\AutoHotkey Automation Scripts\Look Up Words.ahk")
F3::
Run %UserProfile%\Dropbox\AutoHotkey Automation Scripts\Look Up Words.ahk
Return
#If
Its job is to run in the background, and reload another script called "Look Up Words.ahk" when I press F3, if and only if the script isn't already running. Previously, I always spell out the entire path, such as "C:\Users\<my name>\Dropbox\AutoHotkey Automation Scripts\Look Up Words.ahk," since I've only ever used it on 1 computer, and the script work fine.

But now, I've moved computer, and my user name changed. To future-proof the script against future moves, I've decided to change all the hard path to variable path as such. After the change, the script no longer work!

Curiously enough, the "Run" command works fine. It managed to load out the correct script. It's only the "WinExist" command that's giving me trouble.

Is there a way to fix this? Or do I have to put up with using the hard path :(?

Re: winexist can't detect %UserProfile%  Topic is solved

Posted: 18 Apr 2022, 04:23
by gregster
Functions require expression style syntax:

Code: Select all

#If !WinExist(UserProfile "\Dropbox\AutoHotkey Automation Scripts\Look Up Words.ahk")

Re: winexist can't detect %UserProfile%

Posted: 18 Apr 2022, 04:35
by vkhu
gregster wrote:
18 Apr 2022, 04:23
Functions require expression style syntax:

Code: Select all

#If !WinExist(UserProfile "\Dropbox\AutoHotkey Automation Scripts\Look Up Words.ahk")
TYSM!

Just for future reference, how was "Run" able to accept the "%UserProfile%\..." path directly without needing the change like "WinExist"?

Re: winexist can't detect %UserProfile%

Posted: 18 Apr 2022, 04:46
by gregster
Run is a a command, not a function. (Functions are the ones with a parameter list in parentheses)

Re: winexist can't detect %UserProfile%

Posted: 18 Apr 2022, 04:55
by vkhu
Thank you for clearing that up!