winexist can't detect %UserProfile%
Posted: 18 Apr 2022, 04:21
I have a script like so
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
?
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
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
![Sad :(](./images/smilies/icon_e_sad.gif)