我正在尝试在 AutoHotKeys 中使用相对路径,以便可以 check out 源代码管理并且热键仍然有效。
使用 %A_WorkingDir%
给我脚本的位置。从那里我需要向上移动一个目录并向下导航到我需要运行的脚本。
我试过:
^!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
除非没有其他办法,否则我真的不想对工作目录进行任何字符串操作来强制执行它?
谢谢你的帮助
最佳答案
试试
运行 %A_WorkingDir%\..\locationOf\script.cmd
或者
运行“%A_WorkingDir%\..\locationOf\script.cmd”
或者
运行 %comspec%/k "%A_WorkingDir%\..\locationOf\script.cmd"
正如 BGM 所说:
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.
解决方案:
SetWorkingDir, %A_ScriptDir%
关于autohotkey - 我如何使用 AutoHotkeys 的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22468224/