Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use relative paths with AutoHotkeys

Tags:

autohotkey

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

like image 826
Kurtis Avatar asked Oct 31 '25 04:10

Kurtis


1 Answers

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%

like image 79
Joe DF Avatar answered Nov 04 '25 07:11

Joe DF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!