Question

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

Was it helpful?

Solution

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%

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top