binocular222 wrote:This makes me love AHK more. I've never made wrong quoting in AHK.
Double quote for string; no quote for the rest. No double-triple quotes, no single quote, no single-doble quote. Quite simple.
I'm sorry but I have to rain on this parade.. just like XY, AHK CAN be that "simple", but it does not HAVE to be.
Just look:
http://www.autohotkey.com/docs/Variable ... te]Storing values in variables: To store a string or number in a variable, there are two methods: traditional and expression. The traditional method uses the equal sign operator (=) to assign unquoted literal strings or variables enclosed in percent signs. For example:
MyNumber = 123
MyString = This is a literal string.
CopyOfVar = %Var% ; With the = operator, percent signs are required to retrieve a variable's contents.
By contrast, the expression method uses the colon-equal operator (:=) to store numbers, quoted strings, and other types of expressions. The following examples are functionally identical to the previous ones:
MyNumber := 123
MyString := "This is a literal string."
CopyOfVar := Var ; Unlike its counterpart in the previous section, percent signs are not used with the := operator.[/quote]
Strings are sometimes quoted but not always.Retrieving the contents of variables: Like the two methods of storing values, there are also two methods for retrieving them: traditional and expression. The traditional method requires that each variable name be enclosed in percent signs to retrieve its contents. For example:
MsgBox The value in the variable named Var is %Var%.
CopyOfVar = %Var%
By contrast, the expression method omits the percent signs around variable names, but encloses literal strings in quotes. Thus, the following are the expression equivalents of the previous examples:
MsgBox % "The value in the variable named Var is " . Var . "." ; A period is used to concatenate (join) two strings.
CopyOfVar := Var
Variables are sometimes enclosed in percents and sometimes not.if (CurrentSetting > 100 or FoundColor <> "Blue")
MsgBox The setting is too high or the wrong color is present.
In the example above, "Blue" appears in quotes because it is a literal string. To include an actual quote-character inside a literal string, specify two consecutive quotes as shown twice in this example: "She said, ""An apple a day."""
Oh there's double-quotes too!
The common parlance for this usage is to "escape" the significant characters, but try searching that page for "escape" when you don't remember whether AHK wants doubled-quotes, slashed-quotes, or backticked-quotes. Fortunately, they do explain escaping
here but no mention of strings or quotes.
The biggest cause for confusion in XY is quoting the application and arguments in a Run/Open command. Unfortunately, this is a sore point in AHK as well:
http://www.autohotkey.com/docs/commands ... m[quote]To pass parameters, add them immediately after the program or document name. If a parameter contains spaces, it is safest to enclose it in double quotes (even though it may work without them in some cases).[/quote]
When running a program via Comspec (cmd.exe) -- perhaps because you need to redirect the program's input or output -- if the path or name of the executable contains spaces, the entire string should be enclosed in an outer pair of quotes. In the following example, the outer quotes are shown in red and all the inner quotes are shown in black:
Run %comspec% /c ""C:\My Utility.exe" "param 1" "second param" >"C:\My File.txt""
Ooff! I love AHK as well, though I'm not using it as much these days, but I'm not so sure it's a better example of handling these intricacies.
If there is anything to take away from this it's that designing programming languages is hard!