Running Sandbox Browser: Unexpected colon for V2, but not V1

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
CuriousDad
Posts: 74
Joined: 21 Mar 2023, 11:23

Running Sandbox Browser: Unexpected colon for V2, but not V1

Post by CuriousDad » 25 Mar 2023, 23:10

Hello.

I started making hot keys for many of the programs that I use on a day to day basis. I copied the file path for the programs and had no problems with getting everything to work. I decided to use the debugging feature on SciTE4AutoHotKey and I guess it debugs using version 2. I started putting brackets around all the files that I wanted to open. However, it noted that there was an error for me trying to open Firefox through SandboxIE Plus. The script works for version 1, but not version 2. I get an error stating that there was an unexpected colon. The following line has the error in V2.

Code: Select all

^#Numpad5::
{run "C:\Program Files\Sandboxie-Plus\Start.exe" /box:DefaultBox "C:\Program Files\Mozilla Firefox\firefox.exe"
	}
return
I don't know where to begin in figuring out why the unexpected colon is a problem in V2, but not V1. I currently force the script to run in version 1 until I learn why this registers as an error.


Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

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

Re: Running Sandbox Browser: Unexpected colon for V2, but not V1

Post by boiler » 25 Mar 2023, 23:54

Expressions are used throughout v2. You have to put quotes around literal strings. This case is probably best handled using single quotes around the whole thing like this:

Code: Select all

^#Numpad5::
{run '"C:\Program Files\Sandboxie-Plus\Start.exe" /box:DefaultBox "C:\Program Files\Mozilla Firefox\firefox.exe"'
	}
return
…because it makes the the whole thing a string with some parts of it having quotation marks around text within that quoted string.

And that is a very different result than I’d you just added double quotes around the part that was unquoted before because then you’d have several string segments concatenated with no spaces between them and without quotes arou d any of them. To help you visualize it, run this demonstration of the difference:

Code: Select all

MsgBox "C:\Program Files\Sandboxie-Plus\Start.exe" "/box:DefaultBox" "C:\Program Files\Mozilla Firefox\firefox.exe"
MsgBox '"C:\Program Files\Sandboxie-Plus\Start.exe" /box:DefaultBox "C:\Program Files\Mozilla Firefox\firefox.exe"'

It may seem very different than v1 at first, but if you just consider the fact that all parameters are expressions, including this parameter of the Run function, even your v1 knowledge should lead you to see why your code would produce an error.

The part that may be new to you is that you can enclose literal strings in v2 with either single quote characters ' or double quote characters ", and when you use one, the other can be used inside that defined string un-escaped as a literal character.

CuriousDad
Posts: 74
Joined: 21 Mar 2023, 11:23

Re: Running Sandbox Browser: Unexpected colon for V2, but not V1

Post by CuriousDad » 27 Mar 2023, 16:41

Thank you. I just started using AutoHotkey last week. I don't know how I would have easily figured it out. I am thankful that people such as yourself are able to help me. I'm not a programmer in any way and I'm still trying to figure out stuff using the online manual.

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

Re: Running Sandbox Browser: Unexpected colon for V2, but not V1

Post by boiler » 27 Mar 2023, 17:10

I think displaying the results of expressions in a MsgBox is a good way for you to use to visualize what the expression is actually doing. Then over time, the reasons why will become more evident and will become ingrained in your thinking.

CuriousDad
Posts: 74
Joined: 21 Mar 2023, 11:23

Re: Running Sandbox Browser: Unexpected colon for V2, but not V1

Post by CuriousDad » 27 Mar 2023, 21:29

I'll try that. Thank you.

Post Reply

Return to “Ask for Help (v2)”