1

I'd like to run the AHK script with arguments, like:

AutoHotkeyU64 file.ahk arg1 arg2

Then access these variables as part of the script, e.g.

MsgBox, %arg1%, %arg2%

How this can be achieved?

1

The command line parameters are stored in the variables %1%, %2%, and so on. So for example:

MsgBox, %1%, %2%

Since version v1.1.27+, input parameters are stored as an array in the built-in variable A_Args as an array.

Here is the example:

for n, param in A_Args  ; For each parameter:
{
    MsgBox Parameter number %n% is %param%.
}

Legacy: The command line parameters are also stored in the variables %1%, %2%, and so on, as in versions prior to [v1.1.27]. In addition, %0% contains the number of parameters passed (0 if none). However, these variables cannot be referenced directly in an expression because they would be seen as numbers rather than variables.

Source: Passing Command Line Parameters to a Script.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.