Problem With Opening File Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Problem With Opening File

Post by Alexander2 » 02 Dec 2021, 11:20

The following command returns an error message, even though the path is specified correctly:

Code: Select all

Run, F:\_Software (Programs, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk
Do you know what may be the reason why AutoHotkey is unable to open the .exe file with the use of its shortcut?
image_2021-12-02_191939.png
image_2021-12-02_191939.png (10.12 KiB) Viewed 591 times

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Problem With Opening File

Post by boiler » 02 Dec 2021, 11:23

The comma is the problem because commas are parameter separators. Either escape it:

Code: Select all

Run, F:\_Software (Programs`, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk

...or use expression syntax by using a forced expression:

Code: Select all

Run, % "F:\_Software (Programs, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk"

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Problem With Opening File

Post by Alexander2 » 03 Dec 2021, 11:45

boiler wrote:
02 Dec 2021, 11:23
The comma is the problem because commas are parameter separators. Either escape it:

Code: Select all

Run, F:\_Software (Programs`, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk
...or use expression syntax by using a forced expression:

Code: Select all

Run, % "F:\_Software (Programs, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk"
Thank you. I have tried using the following command, but a message appears again:

Code: Select all

Run, % "F:\_Software (Programs, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk"
Untitled.png
Untitled.png (16.26 KiB) Viewed 526 times

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Problem With Opening File  Topic is solved

Post by boiler » 03 Dec 2021, 13:05

It is apparently because your file name contains spaces, especially after the .exe, so it thinks it's supposed to run the specified .exe file (which doesn't exist at that location) with the argument - Shortcut.lnk passed to it. So to run the .lnk file, you need to enclose the whole thing in quotes, which in expression syntax, looks like this:

Code: Select all

Run, % """F:\_Software (Programs, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk"""
(the outermost pair of quotes mark the beginning and end of the string, while each pair of "" inside the string is how a quotation mark inside of a literal string is escaped)


In legacy syntax, it would be like this:

Code: Select all

Run, "F:\_Software (Programs`, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk"
(notice the comma is still escaped in legacy syntax even when enclosed in quotes)


In both cases, it is telling the Run command to use the following string, including the quotation marks:
"F:\_Software (Programs, Applications)\Timer\2010\shortcuts\_4. general purpose.exe - Shortcut.lnk"

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Problem With Opening File

Post by Alexander2 » 04 Dec 2021, 09:04

Thank you. I would have never realized that the specified path has to be enclosed within as many as three pairs of quotations marks in order for the Run command to work. I will now always use this syntax with all Run commands in order to prevent the occurrence of the same issue at any time again.

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Problem With Opening File

Post by boiler » 04 Dec 2021, 10:42

Instead of thinking of it as three quotation marks in a row, you should just think of it as including a quotation mark inside a quoted string. The way you escape a quotation mark inside a quoted string is by preceding it with another one. It only happens to be three in a row because they happen to follow the opening quotation mark and precede the closing quotation mark.

The following example where the quotation marks appear in the middle of the string may make it easier to see what’s happening:

Code: Select all

Str := "Please enter ""FREE"" in the promotion code field."
MsgBox, % Str
The resulting MsgBox displays: Please enter "FREE" in the promotion code field.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Problem With Opening File

Post by Alexander2 » 05 Dec 2021, 11:56

boiler wrote:
04 Dec 2021, 10:42
Instead of thinking of it as three quotation marks in a row, you should just think of it as including a quotation mark inside a quoted string. The way you escape a quotation mark inside a quoted string is by preceding it with another one. It only happens to be three in a row because they happen to follow the opening quotation mark and precede the closing quotation mark.

The following example where the quotation marks appear in the middle of the string may make it easier to see what’s happening:

Code: Select all

Str := "Please enter ""FREE"" in the promotion code field."
MsgBox, % Str
The resulting MsgBox displays: Please enter "FREE" in the promotion code field.
Yes, I can see now that additional quotation marks are to be used in order to cause the program to view the rest of the quotation marks as part of the text rather than as operators.

Post Reply

Return to “Ask for Help (v1)”