将命令字符串传递给 AutoHotkey

Pass in a command string to AutoHotkey

我想 运行 一个 AutoHotkey 命令。脚本似乎有点矫枉过正。

在 bash 和 powershell 中,您可以 运行 通过将命令作为字符串传递给 shell:

pwsh -Command ls
bash -c ls

有没有办法用 AutoHotKey.exe 做到这一点?在documentation中,我看到的是你可以传递一个脚本文件的名字来执行。如果 powershell 支持进程替换 <(ls),我可以做

AutoHotKey.exe <(echo "ls")

但我不认为有一种方法可以做到这一点shell。

除了creating a complicated version of process substitution myself还有其他方法吗?

linked docs状态:

[v1.1.17+]: Specify an asterisk (*) for the filename to read the script text from standard input (stdin). For an example, see ExecScript().

例如,来自 PowerShell:

'MsgBox % "Hello, world."' | AutoHotKey.exe *

我不确定您是在寻找其他答案的内容,还是在寻找我将要写的内容:
您可以将参数传递给 AHK 脚本,然后从内置变量 A_Args.

中找到这些参数

示例 AHK 脚本:

for each, arg in A_Args
    output .= arg "`n"
MsgBox, % output

PowerShell 命令:

& "C:\Path\To\My\Script.ahk" arg1 arg2 "this is the 3rd argument" arg4

如果您安装了 AHK,就会出现这种情况。如果您有一些可移植的 AHK 设置,您可以将示例脚本传递给 AutoHotkey.exe,然后传递所需的参数。