I'm trying to use relative path in AutoHotKeys so the source control can be checked out and the hotkeys will still work.
Using %A_WorkingDir% gives me the location of the script. From there I need to move up one directory and nagivate down to the script I need to run.
I have tried:
^!a::
Path = %A_WorkingDir%
Run %Path%\..\locationOf\script.cmd
^!a::
Path = %A_WorkingDir%\..
Run %Path%\locationOf\script.cmd
^!a::
Path = %A_WorkingDir% \..
Run %Path%\locationOf\script.cmd
^!a::
Path = %A_WorkingDir% "\.." ; Also removed the space between % and " -> %A_WorkingDir%"\.." but didn't work
Run %Path%\locationOf\script.cmd
I don't really want to do any string manipulation on the working dir to force it unless there is no other way?
Thanks for your help
Try
Run %A_WorkingDir%\..\locationOf\script.cmd
Or
Run "%A_WorkingDir%\..\locationOf\script.cmd"
Or
Run %comspec% /k "%A_WorkingDir%\..\locationOf\script.cmd"
As BGM has said :
Keep in mind that the workingdir can also be changed via a windows launcher or shortcut. If you use a launcher like JetToolbar (my favourite) it sets the workingdir to its own application directory by default. It might be a good idea for the script to set the workingdir to the scriptdir or just use scriptdir instead.
Solution :
SetWorkingDir, %A_ScriptDir%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With